Thanks alot guys especially Greg. I got it working in the main script but still can't get it going in a module it doesn't
know what I'm refering to when I use wdDoc but it does in the main script so that'll do. If it ain't broke.....
This is what I ended up using anyway.
Code:
arrTerms = Split("(\<italics\>)(*)(\<italics/\>)|(\<bold\>)(*)(\<bold/\>)|(\<indent\>)(*)(\<indent/\>)", "|")
For lngIndex = 0 To UBound(arrTerms)
Set wdRng = wdDoc.Range
With wdRng.Find
.Text = arrTerms(lngIndex)
.MatchWildcards = True
Select Case lngIndex
Case 0: .Replacement.Font.Italic = True
Case 1: .Replacement.Font.Bold = True
Case 2: .Replacement.ParagraphFormat.LeftIndent = 72
End Select
.Replacement.Text = "\2"
.Execute Replace:=wdReplaceAll
End With
Next
This seems like super great code that I will use again but i can't really work out how it works could you please break it down for me. And say add another section that replaces <tab> with a vbtab. So I can compare and see how it works. Any explanations would be great. Below I have sort of explained how I see it. Actually probably
better stated how I don't see it.
Code:
Code:
'So the first line you are creating a list/matrix
with a single row and defining it as arr terms. I don't really
get what the Split and the l or all the brackets and asterisks
and backslashes are doing though.
arrTerms = Split("(\<italics\>)(*)(\<italics/\>)|(\<bold\>)(*)(\<bold/\>)|(\<indent\>)(*)(\<indent/\>)", "|")
'Creating a loop which is based on variable IngIndex
running through as many times as there are items in the list
For lngIndex = 0 To UBound(arrTerms)
' Setting Range as whole document?
Set wdRng = wdDoc.Range
With wdRng.Find
'Find the term from the list for example <italics>and I start to very lost
.Text = arrTerms(lngIndex)
'I assume this means it has to be exact match
.MatchWildcards = True
'Have no idea what is going on here cause I can't work out where
you have actually selected the text between the two terms
that is <italics> and <italics/>
Select Case lngIndex
Case 0: .Replacement.Font.Italic = True
Case 1: .Replacement.Font.Bold = True
Case 2: .Replacement.ParagraphFormat.LeftIndent = 72
End Select
'I believe this line deletes all the arrterms in the document
but have no idea how or why or what "\2" is
.Replacement.Text = "\2"
.Execute Replace:=wdReplaceAll
End With
"Goes to next in list
Next
Would be great to understand it so I can use it in other instances for example I think I will need it for <tab> at some stage. Once again thanks heaps for all the help my project is really coming along.