![]() |
|
#1
|
|||
|
|||
![]()
I'll add a little to Paul's explanation and while I'm at it concede, as is typically the case, his code is more concise than mine.
RE the first line (and the declaration). Paul and I both used a VBA function to return an array (an array is sort of like a matrix or list). Paul used "Array" which returns a variant containing an array (the element could be strings, longs, doubles, whatever) and I used "Split" which returns a zero-based, one-dimensional array containing a specified number of substrings. In the example below, my elements are "A, B and C" ("A|B|C")delimited using the "|" character. I could have just as easily used "A,B,C" "," where the elements were delimited with a comma. In this case I don't see where either are more or less concise than the other and just a preference. Using Array, the elements could have been the strings A, B and C or longs 1, 2, 3 or whatever. Code:
Sub ArraySplitDiff() Dim arr Dim arrString() As String arr = Array(1, 2, 3) arr = Array("A", "B", "C") arrString = Split("A|B|C", "|") End Sub The first group defines the leading “<” and the term from the array. When using wildcards, some characters “are wildcard” characters so when you physically want to find the implicit character you precede it with “\”. So the first group looks for “<italics or <bold or <indent etc. The second group defines the trailing “>” The third group defines anything between the tags. Where Paul dazzles, is when he follows the third group with the group number for the first group, the expression to find the “\” in the second half for the tag and the group number for the second group. Naturally Paul then assigns the group 3 as the replacement text. I had used three groups as well but in my expression group 2 was the part that defined everything between the tags. Adding something else is simply at this point: Code:
Sub Demo() Dim arrTerms(), i As Long arrTerms = Array("italics", "bold", "indent", "tab") With ActiveDocument.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 Case 3: .Replacement.Text = Chr(9) End Select .Execute Replace:=wdReplaceAll Next End With End Sub |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Adding tables to Created word document whilst other word document open Help | rpb925 | Word VBA | 18 | 03-30-2016 04:45 PM |
![]() |
JennJenn79 | Word | 1 | 07-16-2015 09:34 PM |
![]() |
TDOG | Word | 1 | 10-12-2014 03:37 PM |
Copy format created by a conditional formatting | spk | Excel | 2 | 04-10-2013 04:41 AM |
Word crashing on "sort" routine | Kayale | Word | 0 | 04-12-2010 04:54 PM |