![]() |
|
#2
|
||||
|
||||
|
The following macro allows you to browse to a folder containing the documents you want to process, then replace a given string in all documents in that folder automatically.
Code:
Sub UpdateDocuments()
Application.ScreenUpdating = False
Dim strFolder As String, strFile As String, strDocNm As String, wdDoc As Document
strDocNm = ActiveDocument.FullName
strFolder = GetFolder
If strFolder = "" Then Exit Sub
strFile = Dir(strFolder & "\*.doc", vbNormal)
While strFile <> ""
If strFolder & "\" & strFile <> strDocNm Then
Set wdDoc = Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False)
Call SearchAndReplace(wdDoc)
wdDoc.Close SaveChanges:=True
End If
strFile = Dir()
Wend
Set wdDoc = Nothing
Application.ScreenUpdating = True
End Sub
Function GetFolder() As String
Dim oFolder As Object
GetFolder = ""
Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0)
If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
Set oFolder = Nothing
End Function
Sub SearchAndReplace(wdDoc As Document)
With wdDoc
'Your document-specific code goes here
End With
End Sub
PS: Asking others to do coding for you that you're being assessed on is called cheating. The only reason I posted the above (hopefully too late to be of use) is because a search of this forum (which you're apparently too lazy to do) would turn up plenty of threads using almost identical code. Thread closed.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Macro to Open to a Website When No Document Is Open
|
lostinwebspace | Word VBA | 1 | 02-13-2016 10:28 AM |
| Help - Need Macro to Apply Blur | SSL | PowerPoint | 6 | 07-26-2015 08:59 AM |
URGENT: macro icons don't work when 'save as'
|
AndyDDUK | PowerPoint | 9 | 11-21-2012 08:21 AM |
Macro to apply style to selected tables
|
ubns | Word | 1 | 08-02-2012 04:09 AM |
| macro to open another document | coconutt | Word VBA | 1 | 06-11-2012 04:39 AM |