J
Joel Finkel
Folks,
I have a VBA script that I use to convert articles that I receive in Word format to simple (and I mean simple) HTML. The script simply performs a long series of search-and-replaces by using the Selection.Find object.
However, there are some strings that I need to convert that cannot be parsed without using a more robust regular expression parser. For example, I need to find a single line that comprises 8 or fewer words and that is followed by only a single ^p and replace it with "^p<h3>the words</h3>^p".
I added a reference to the Microsoft VBScript Regular Expressions 5.5 and created the following Sub:
Sub DoSectionHeaders(ByRef s As String)
Set re = New RegExp
re.Pattern = "\r(\w{1,8})\r{1}"
re.IgnoreCase = True
re.Global = True
s = re.Replace(s, "\r<h3>\1</h3>\r")
End Sub
My question: How do I pass the entire formatted text into this Sub so it can be processed?
I tried this:
Call DoSectionHeaders(Selection.FormattedText)
But Selection.FormattedText is an empty string.
Thanks in advance for all suggestions. Oh yes, I am using Word 2003.
Joel Finkel
(e-mail address removed)
I have a VBA script that I use to convert articles that I receive in Word format to simple (and I mean simple) HTML. The script simply performs a long series of search-and-replaces by using the Selection.Find object.
However, there are some strings that I need to convert that cannot be parsed without using a more robust regular expression parser. For example, I need to find a single line that comprises 8 or fewer words and that is followed by only a single ^p and replace it with "^p<h3>the words</h3>^p".
I added a reference to the Microsoft VBScript Regular Expressions 5.5 and created the following Sub:
Sub DoSectionHeaders(ByRef s As String)
Set re = New RegExp
re.Pattern = "\r(\w{1,8})\r{1}"
re.IgnoreCase = True
re.Global = True
s = re.Replace(s, "\r<h3>\1</h3>\r")
End Sub
My question: How do I pass the entire formatted text into this Sub so it can be processed?
I tried this:
Call DoSectionHeaders(Selection.FormattedText)
But Selection.FormattedText is an empty string.
Thanks in advance for all suggestions. Oh yes, I am using Word 2003.
Joel Finkel
(e-mail address removed)