Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / June 2005

Tip: Looking for answers? Try searching our database.

VBA and regular expression to search for ranges of text

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
enda_ridge@excite.com - 27 Jun 2005 15:50 GMT
Hi,
I'd be very grateful for help with the following.

I have a text file open in Word. I need an example of how to use a
regular expression to search for ranges of text that begin with
'\begin{figure}' and end with '\end{figure}' inclusive.
\begin{figure}
Any text can go here etc etc etc
\end{figure}

Once this is found, I would like to convert it to a Word Range object
and then continue the regular expression search from the next point in
the document.

Thanks in advance,

Enda
Helmut Weber - 27 Jun 2005 16:07 GMT
Hi Enda,

lke this:

Sub Test7884()
Dim rTmp As Range
Set rTmp = ActiveDocument.Range
ResetSearch
With rTmp.Find
  .Text = "\\begin\{figure\}*\\end\{figure\}"
  .MatchWildcards = True
  While .Execute
     rTmp.Select ' for testing
  Wend
ResetSearch
End With
End Sub
' ----
Public Sub ResetSearch()
With Selection.Find
  .ClearFormatting
  .Replacement.ClearFormatting
  .Text = ""
  .Replacement.Text = ""
  .Forward = True
  .Wrap = wdFindContinue
  .Format = False
  .MatchCase = False
  .MatchWholeWord = False
  .MatchWildcards = False
  .MatchSoundsLike = False
  .MatchAllWordForms = False
  ' plus some more if needed
  .Execute
End With
End Sub

You don't have to convert what you found to a range.
It is a range already. The question is, what do want to do with it.

Greetings from Bavaria, Germany

Helmut Weber, MVP, WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
enda_ridge@excite.com - 28 Jun 2005 13:43 GMT
Hi Helmut,
Thanks for your help.
Enda
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.