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 / September 2007

Tip: Looking for answers? Try searching our database.

look in several folders for a single document with a specific name

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ryguy7272 - 27 Sep 2007 17:01 GMT
I have used the macro below with great success!  I am curious to know how to
modify the code to get the macro to look in several folders for a single
document.  For instance, I may have Folder#1, Folder#2, Folder#3, Folder#4,
etc., and maybe as many as 50 different folders within one folder.  How can I
get the macro to search through each of these folders and check for a certain
document, with a name such as “Coverage Terms”?  If a document with a certain
name is found, I’d like to copy/paste, append, whatever, to my main document
(that I run the macro from).  I guess I need a line or two of code right
after the line:
.LookIn = "F:\Microsoft Word"

Sub Append()
Dim i As Long
Application.ScreenUpdating = False
Documents.Add
With Application.FileSearch
'Search in foldername
.LookIn = "F:\Microsoft Word"
.SearchSubFolders = False
.FileName = "*.doc"
.Execute
For i = 1 To .FoundFiles.Count
If InStr(.FoundFiles(i), "~") = 0 Then
Selection.InsertFile FileName:=(.FoundFiles(i)), _
ConfirmConversions:=False, Link:=False, Attachment:=False
Selection.InsertBreak Type:=wdPageBreak
End If
Next i
End With
End Sub

Signature

RyGuy

ryguy7272 - 27 Sep 2007 20:40 GMT
Got it with 2 extremely minor changes:
.SearchSubFolders = True
.FileName = "Updates*.doc"

Sub Append()
Dim i As Long
Application.ScreenUpdating = False
Documents.Add
With Application.FileSearch
.LookIn = "F:\Microsoft Word"
.SearchSubFolders = True
.FileName = "Updates*.doc"
.Execute
For i = 1 To .FoundFiles.Count
If InStr(.FoundFiles(i), "~") = 0 Then
Selection.InsertFile FileName:=(.FoundFiles(i)), _
ConfirmConversions:=False, Link:=False, Attachment:=False
Selection.InsertBreak Type:=wdPageBreak
End If
Next i
End With
End Sub

I'm more used to VBA in Excel; VBA in word is still quite intimidating for me.
Hope this (simple) solution helps others.

Signature

RyGuy

> I have used the macro below with great success!  I am curious to know how to
> modify the code to get the macro to look in several folders for a single
[quoted text clipped - 26 lines]
> End With
> End Sub
 
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.