Microsoft 365 and Office | Word | For home | Windows
A family of Microsoft word processing software products for creating web, email, and print documents.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hell from Steve
The below is an excel version, Can I please have a "word" version
Sub Test()
Dim Words, I As Long
Words = [{"Omalley", "Thurlow O'malley", "T Ebbett", "P & T Ebbett", "B Kelso", "K & B Kelso", "R Foote", "B & R Foote"}]
For I = 1 To UBound(Words) Step 2
Cells.Replace Words(I), Words(I + 1), xlWhole
Next I
End Sub
To convert the provided Excel VBA code to Word VBA, you would need to adjust the syntax and object references accordingly. Below is a Word version of your code that performs a similar function, replacing specific words in the active document:
Sub Test()
Dim Words As Variant, I As Long
Words = Array("Omalley", "Thurlow O'malley", "T Ebbett", "P & T Ebbett", "B Kelso", "K & B Kelso", "R Foote", "B & R Foote")
For I = LBound(Words) To UBound(Words) Step 2
With ActiveDocument.Content.Find
.Text = Words(I)
.Replacement.Text = Words(I + 1)
.Wrap = wdFindContinue
.Execute Replace:=wdReplaceAll
End With
Next I
End Sub
This code uses the Find and Replacement objects to search for each word in the Words array and replace it with the corresponding word. Make sure to run this macro in a Word document where you want the replacements to occur.
Hello AI I thank you