R
ryguy7272
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
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