![]() |
|
#1
|
|||
|
|||
|
I've come across an issue with the code I use to format a set of definitions into our house style. At the moment the code I use (not the below code) only looks for the the word 'means' and inserts a tab before it but Definition wording often has other common words e.g. 'incudes', 'has the meaning' or 'any' so when I run the code these remain unchanged.
Would the best approach be to put these words into an array to look for the first instance in each paragraph and insert a tab before them. I'm trying to get the code below to work. Am I on the right track or is there a simpler way to achieve what I need the code to do? Before Before.JPG After After.JPG Before - Insert Tab.docx Code:
Sub InsertTab_Before_FirstInstance()
Dim oRng As Word.Range
Dim arrWords
Dim i As Long
arrWords = Array("means", "includes", "has", "any")
For i = 0 To UBound(arrWords)
Set oRng = ActiveDocument.Range
With oRng.Find
.ClearFormatting
.Replacement.ClearFormatting
.text = arrWords(i)
.MatchWholeWord = True
.Replacement.text = ChrW(9) & arrWords(i)
.Execute Replace:=wdReplaceOne
End With
Next
End Sub
|
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
VBA help non breaking spaces for array of words not working correctly
|
Shelley Lou | Word VBA | 2 | 03-08-2023 03:15 AM |
Macro to insert certain words if the number of words than 20
|
laith93 | Word VBA | 6 | 10-28-2022 01:12 AM |
Insert words before and after any italics
|
benfarley | Word VBA | 1 | 03-30-2022 08:35 PM |
| An array of words from a document knowing the font style | Kreol2013 | Word VBA | 0 | 07-08-2013 01:29 AM |
Convert String Array to Integer Array from a User Input?
|
tinfanide | Excel Programming | 4 | 12-26-2012 08:56 PM |