Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 01-28-2020, 12:41 PM
rmoyar rmoyar is offline Static Folder Locations to Automate a Find and Replace using Word VBA Windows 10 Static Folder Locations to Automate a Find and Replace using Word VBA Office 2019
Novice
Static Folder Locations to Automate a Find and Replace using Word VBA
 
Join Date: Jan 2020
Posts: 4
rmoyar is on a distinguished road
Talking Static Folder Locations to Automate a Find and Replace using Word VBA

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]
Reply With Quote
 

Tags
copy and paste, looping, word vba macro



Similar Threads
Thread Thread Starter Forum Replies Last Post
Static Folder Locations to Automate a Find and Replace using Word VBA Word find and replace 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
Static Folder Locations to Automate a Find and Replace using Word VBA Find & replace footer text in a folder of Word 2010 documents kennethc Word 3 03-28-2015 02:49 AM
Static Folder Locations to Automate a Find and Replace using Word VBA Bad view when using Find and Find & Replace - Word places found string on top line 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

Other Forums: Access Forums

All times are GMT -7. The time now is 06:53 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft