![]() |
#3
|
||||
|
||||
![]()
Look carefully at this code and step through it line by line to work out what each line is doing. Your code sample shows a lot of useless activities going on. There are some key differences in this code when compared to yours and those differences can be important.
Code:
Sub bfMassReplaceLoopTest() Dim wDoc As Word.Document, i As Integer Dim fso As Object, mySource As Object, file As Object Application.ScreenUpdating = False On Error Resume Next Set fso = CreateObject("Scripting.FileSystemObject") Set mySource = fso.GetFolder("C:\Users\rmoyar\Desktop\TestEnvironment\Macro Testing\Test 1") For Each file In mySource.Files 'loop through the directory If file.Name Like "*.doc*" And InStr(1, file.Name, "$") = 0 Then '$ is temp file mask i = i + 1 Debug.Print i, file.Name Set wDoc = Documents.Open(FileName:=file, ConfirmConversions:=False, ReadOnly:=False, _ AddToRecentFiles:=False, Visible:=True, Format:=wdOpenFormatAuto, XMLTransform:="") With wDoc.Find .ClearFormatting .Replacement.ClearFormatting .Text = " 120 BF" 'Find What .Replacement.Text = " 125 BF" 'Replace With .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchByte = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False .Execute Replace:=wdReplaceAll End With wDoc.Close SaveChanges:=True End If Next file Application.ScreenUpdating = True MsgBox "Task Complete, please check files", vbInformation End Sub
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
Tags |
copy and paste, looping, word vba macro |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
ganesang | Word | 4 | 11-27-2018 12:04 AM |
In Find and Replace, can Word stop after each Replace? | wardw | Word | 1 | 06-08-2017 02:47 PM |
![]() |
kennethc | Word | 3 | 03-28-2015 02:49 AM |
![]() |
paulkaye | Word | 4 | 12-06-2011 11:05 PM |
Looking for a way to automate moving emails to folder | middletree | Outlook | 1 | 09-28-2010 01:24 PM |