![]() |
#1
|
|||
|
|||
![]()
First Time poster here, thank you all for the help in advance. I am very stuck on this situation. I have modified (started with Do While - lack of experience = dead end) several times.
This is the closest I think I have been, but basically I have truncated the code a bit... There are 100 different " xx BF" replacements that will need to happen on ~ 100 different Folder locations (want to hit the button and retire for the night). immediate window indicates 1 2 1 2 2 2 So it hits the first Debug.Print = 1, then doesn't print the file.name but still proceeds and prints the second debug.print i = 2 (after the ++) But then goes into the next for loop? There are 10 .doc files in the listed file path for testing [Sub bfMassReplaceLoopTest() Dim wApp As Word.Application Dim wDoc As Word.Document Dim mySource As Object Dim myVar(0 To 2000) As String Application.ScreenUpdating = False On Error Resume Next Set mySource = obj.GetFolder.Items.Item.path("C:\Users\rmoyar\Des ktop\TestEnvironment\Macro Testing\Test 1") i = 1 For Each file In mySource.Files 'loop through the directory If Len(file.Name) > 0 And InStr(1, file.Name, "$") = 0 Then '$ is temp file mask Debug.Print i myVar(i) = file.Name i = i + 1 Debug.Print file.Name Debug.Print i End If Next file j = 1 For j = 1 To i Step 1 Debug.Print j Debug.Print i Set Doc = Documents.Open(FileName:=myVar(j), ConfirmConversions:=False, ReadOnly:=False, AddToRecentFiles:=False, Visible:=True, Format:=wdOpenFormatAuto, XMLTransform:="") Windows(myVar(j)).Activate Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = " 120 BF" 'Find What .Replacement.Text = " 125 BF" 'Replace With .Forward = True .Wrap = wdFindAsk .Format = False .MatchCase = False .MatchWholeWord = False .MatchByte = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll ActiveWindow.Close SaveChanges:=True Next Application.ScreenUpdating = True MsgBox "Task Complete, please check files", vbInformation Debug.Print " " Debug.Print " " Debug.Print " " Debug.Print " " End Sub ][/CODE] |
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 |