Microsoft Office Tutorials and References
In Depth Information
Finding and Replacing in Multiple Documents
'Debug.Print FilePath, LinkPath¶
'Suppress screen flicker as much as possible¶
Application.ScreenUpdating = False¶
'Save the user's current macro security setting¶
securitySetting = Application.AutomationSecurity¶
'Suppress macro warnings¶
Application.AutomationSecurity = msoAutomationSecurityLow¶
'Suppress messages, as far as possible¶
Application.DisplayAlerts = wdAlertsNone¶
'Don't allow Automacros to run¶
WordBasic.DisableAutoMacros¶
ProcessFiles FilePath, linkPath¶
'Restore original settings¶
WordBasic.DisableAutoMacros 0¶
Application.DisplayAlerts = wdAlertsAll¶
Application.AutomationSecurity = securitySetting¶
End Sub¶
' * * * * *¶
Function GetFileFolder(DlgTitle As String) As String¶
'Variable declaration¶
Dim dlg As Office.FileDialog¶
'Use the Office FileDialog box to get the path info¶
Set dlg = Application.FileDialog(msoFileDialogFolderPicker)¶
With dlg¶
.AllowMultiSelect = False¶
.ButtonName = "Select Folder"¶
.InitialView = msoFileDialogViewList¶
.Title = DlgTitle¶
'User did not cancel¶
If .Show = -1 Then¶
GetFileFolder = .SelectedItems.Item(1)¶
End If¶
End With¶
End Function¶
' * * * * *¶
Sub ProcessFiles(FilePath As String, linkPath As String)¶
'Variable declaration¶
Dim doc As Word.Document¶
' !Remember to reference Microsoft Scripting Runtime!¶
Dim fso As Scripting.FileSystemObject¶
Dim f As Scripting.Folder, fil As Scripting.File¶
Set fso = CreateObject("Scripting.FileSystemObject")¶
'If the folder exists...¶
If fso.FolderExists(FilePath) Then¶
Set f = fso.GetFolder(FilePath)¶
'Loop through each file in it¶
For Each fil In f.Files¶
'Check if it's a Word document¶
If LCase(fil.Type) = "microsoft word document" Then¶
'If yes, open it¶
Set doc = Documents.Open(fil.Path)¶
Wrd
Search JabSto ::




Custom Search