Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / October 2006

Tip: Looking for answers? Try searching our database.

Working with folders

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Pete - 01 Oct 2006 17:32 GMT
I have a couple of problems I hope someone will be able to help with

Firstly I would like a folder to be created (name inputted in to text
box by end user) then a commanbutton which will then create said folder
at the given path. However at moment all I can achieve is a folder
called textbox1 so nearly there but something amiss.

Secondly when folder is created I would like a list box to be able to
view all folders within above folder, Im working with the code below
and trying to utilise it without much luck, Im aware that this deals
with files rather than folders.

Private Sub UserForm_Initialize()
Dim objFSO As Object, TargetFolder As Object, FC As Object

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set TargetFolder = objFSO.GetFolder("C:\Program Files\Azzmet\Data\RISK
ASSESSMENTS")
Set FC = TargetFolder.Files
HowMany = FC.Count

For Each File In FC
ListBox1.AddItem (File.Name)
Debug.Print File.Name
Next File

Any help would be appreciated

Regards

Pete
Doug Robbins - Word MVP - 01 Oct 2006 20:03 GMT
It would help if you pasted the code that you have.  However, the code that
you would need to create a folder with the name that is entered into
Textbox1 would be

MkDir "c:\" & Textbox1.text

As for getting the names of the folders, See the article "How to get the
names of all the folders in the folder tree, starting from a specified
folder" at:

http://www.word.mvps.org/FAQs/MacrosVBA/ReadFoldersIntoArray.htm

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

>I have a couple of problems I hope someone will be able to help with
>
[quoted text clipped - 27 lines]
>
> Pete
Pete - 02 Oct 2006 07:58 GMT
Hi Doug

Manyhtanks for the info, the code Im using for creating the folder, how
would your code fit in with this?

Private Sub CommandButton1_Click()
Dim fs, f, N
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.CreateFolder("c:\TextBox1.Value\")

Set f = Nothing
Set fs = Nothing

End Sub

Regards

Pete
Doug Robbins - Word MVP - 02 Oct 2006 18:47 GMT
Assuming that

Set f = fs.CreateFolder("c:\TextBox1.Value\")

does create a folder, to get it to create one under the root directory with
the name of the entry in TextBox1, you would use:

Set f = fs.CreateFolder("c:\" & TextBox1.Value)

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

> It would help if you pasted the code that you have.  However, the code
> that you would need to create a folder with the name that is entered into
[quoted text clipped - 39 lines]
>>
>> Pete
Pete - 02 Oct 2006 21:22 GMT
Hi Doug

I have manged to get the code for running through folders to run
however I cant get the folders to be displayed in a list box ?

Regards

Pete
Doug Robbins - Word MVP - 03 Oct 2006 04:40 GMT
Replace the following code in the article to which I referred you:

For i = LBound(FoldersArray) To UBound(FoldersArray)
   ActiveDocument.Range.InsertAfter FoldersArray(i) & vbCr
Next i

with

For i = LBound(FoldersArray) To UBound(FoldersArray)
   [ListBox].AddItem FoldersArray(i)
Next i

replace [ListBox] with a proper reference to the listbox to which you want
to add the folders.
Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

> Hi Doug
>
[quoted text clipped - 4 lines]
>
> Pete
Pete - 03 Oct 2006 16:15 GMT
Hi Doug

Sorry Im missing something here, I now have the following code

Dim FoldersArray As Variant
Dim i As Integer

'Read all subfolders of the specified folder into an array
'by calling the funcGetSubfolders function
FoldersArray = funcGetSubfolders("C:\Windows")

'Put the results (the array values) into the current document if it is
blank,
'or else into a new document
If Len(ActiveDocument.Range.Text) > 1 Then
   Documents.Add
End If
For i = LBound(FoldersArray) To UBound(FoldersArray)
   ListBox1.AddItem FoldersArray(i)
Next i

ActiveDocument.Saved = True

I have tried all varients of placing text within listbox1 code, form
intilize etc so must be doing something wrong?

Regards

Pete
Doug Robbins - Word MVP - 04 Oct 2006 04:50 GMT
The code would normally be in the Initialize() event of the form.  This part
of the code is not required

'Put the results (the array values) into the current document if it is
blank,
'or else into a new document
If Len(ActiveDocument.Range.Text) > 1 Then
   Documents.Add
End If

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

> Hi Doug
>
[quoted text clipped - 25 lines]
>
> Pete
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.