View Single Post
 
Old 03-30-2016, 01:53 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

To explain, I'll start with my own equivalent of Greg's code, as it's a little easier to see what's going on:
Code:
Sub FormatHTML(wdDoc As Document)
Dim arrTerms(), i As Long
arrTerms = Array("italics", "bold", "indent")
With wdDoc.Range.Find
    .MatchWildcards = True
    .Replacement.Text = "\3"
    For i = 0 To UBound(arrTerms)
        .Replacement.ClearFormatting
        .Text = "(\<" & arrTerms(i) & ")(\>)(*)\1/\2"
        Select Case i
            Case 0: .Replacement.Font.Italic = True
            Case 1: .Replacement.Font.Bold = True
            Case 2: .Replacement.ParagraphFormat.LeftIndent = 72
        End Select
        .Execute Replace:=wdReplaceAll
    Next
End With
End Sub
The first line:
Sub FormatHTML(wdDoc As Document)
contains both the name of the subroutine and a reference to the document you want to process.

The line:
arrTerms = Array("italics", "bold", "indent")
defines an array containing three elements. In my code, those elements are just simple words; in Greg's, they're complete wildcard strings.

The lines:
For i = 0 To UBound(arrTerms)
...
Next
set up a loop that processes all the array elements.

The line:
.Text = "(\<" & arrTerms(i) & ")(\>)(*)\1/\2"
turns the array element into a wildcard expression that is the equivalent of the wildcard expression contained in Greg's array.

The block delineated by:
Select Case i
...
End select
tells the code what to use as a replacement parameter for the corresponding array element. The first item is Case 0, because 0 is the normal index number of the first entry in an array.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote