I have a word document containing many html documents as defined by html tags. I would like to create an array or collection of ranges, each range consisting of one html document. For example, here is the Word document:
<html> <head> <title> </title> </head> <body> HTML Doc 1 </body> </html>
<html> <head> <title> </title> </head> <body> HTML Doc 2 </body> </html>
<html> <head> <title> </title> </head> <body> HTML Doc 3 </body> </html>
etc. I would like to populate rngHTMLDocs() As Range with a series of ranges, each range containing the text within each opening and closing html tag.
I have created the following code in an attempt to iterate through the entire document defining these ranges, but it only keeps selecting HTML Doc 1. I think I may be approaching the whole iteration thing in the wrong way. Anyway, here is the code:
Set rngDocContent = ActiveDocument.Content
intCounter = 1
With rngDocContent.Find
.ClearFormatting
.Text = "<html>"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Execute
Do While .Found = True
Set rngTemp = rngDocContent.Duplicate
rngTemp.Select
Selection.Extend
With Selection.Find
.ClearFormatting
.Text = "</html>"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindAsk
.Execute
End With
Set rngHtmlDocs(intCounter) = Selection.Range
Selection.Start = Selection.End
intCounter = intCounter + 1
Loop
End With
In setting the rngDocContent for the entire document, and using wdFindContinue, I had hoped that it would in fact continue searching the document for the next instance of an opening html tag, but that is not the case. Thanks in advance for any help you might provide.