|
-
Aug 31st, 2000, 08:37 AM
#1
Thread Starter
Junior Member
I have a main directory and a number of subdirectories on my hard-drive.
I have a number of MS Word files in the sundirectories. (standard forms and letters etc.) I want to insert my clients name into the footer of each word document in the all the subdirectories.
How do I select each sub-direcory in turn until there are no subdirectories left.
How do I select each Word file in turn until there are no Word files left.
Once I have a Word file open - I have no problem inserting the Client Name text - that I can do. I can also open and close a single Word file - no problem.
Any help would be great.
Graham.
-
Aug 31st, 2000, 08:57 AM
#2
The simpliest and fastest way of doing this without resorting to the API is to use the FileSystemObject.
Set a reference to Microsoft Scripting Runtime and edit the following code sample:
Code:
Private Sub GetWordFiles(sPath As String)
Dim fso As FileSystemObject
Dim sFilename As String
Dim fld As Folder
Set fso = New FileSystemObject
If fso.FolderExists(sPath) Then
sPath = sPath & IIf(Right$(sPath, 1) <> "\", "\", "")
sFilename = Dir(sPath & "*.doc")
Do While Len(sFilename)
MsgBox sPath & sFilename
sFilename = Dir
Loop
For Each fld In fso.GetFolder(sPath).SubFolders
GetWordFiles fld.Path
Next
End If
End Sub
Good luck!
-
Sep 4th, 2000, 04:51 PM
#3
Thread Starter
Junior Member
Thanks for the help.
Graham.
-
Sep 4th, 2000, 06:43 PM
#4
Thread Starter
Junior Member
Joacim,
Can I ask for your help again.
I have used the last bit of code you have given me but I must be doing something stupid.
I am trying to get the code to run on the click of a command button.
It won't let me put the definition (sPath As String) in the title of the procedure and I am getting an error on the GetWordFiles Command.
If you could give me the code for operating from the click of a button I would be most geteful.
Grahm.
-
Sep 5th, 2000, 02:35 AM
#5
Either you copy the entire procedure I gave you in the previous post and call it from the Click event:
Code:
Private Sub Command1_Click()
GetWordFiles("c:\TheFolderWhereTheWordFilesAre")
End Sub
Or you can rewrite the code into the Click event
Code:
Private Sub Command1_Click()
Dim fso As FileSystemObject
Dim sFilename As String
Dim fld As Folder
Dim sPath As String
'Get the path!
'Either hardcode the path or ask the user for it!
sPath = InputBox("Where are the Word files?")
If Len(sPath) = 0 Then
'the User Clicked Cancel
Exit Sub
End If
Set fso = New FileSystemObject
If fso.FolderExists(sPath) Then
sPath = sPath & IIf(Right$(sPath, 1) <> "\", "\", "")
sFilename = Dir(sPath & "*.doc")
Do While Len(sFilename)
MsgBox sPath & sFilename
sFilename = Dir
Loop
For Each fld In fso.GetFolder(sPath).SubFolders
GetWordFiles fld.Path
Next
End If
End Sub
Good luck!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|