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 2007

Tip: Looking for answers? Try searching our database.

regular expression doesn't detect set pattern

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
muyBN - 07 Jun 2007 03:00 GMT
I've got the following code in which I'm trying to use regular expressions:

'at top of module:
Dim Reg As RegExp

'in procedure:
Set Reg = New RegExp

   Reg.Pattern = "\n"
   With Selection
       .MoveDown unit:=wdParagraph, Extend:=wdExtend
       If InStr(LCase(Selection), "address") = 0 Then
           If Selection <> Reg.Pattern Then .MoveDown unit:=wdParagraph,
Extend:=wdExtend
       End If

The selected text is a paragraph mark yet the macro still moves down and
selects the next paragraph (meaning that it detects the original paragraph
mark as not being a paragraph mark). Where am I going wrong? I thought the \n
criteria was supposed to represent any type of line break.

Signature

Bryan

Russ - 07 Jun 2007 20:21 GMT
I believe you are using a VBScripting object to do regular expressions. You
might find more help on that in a different forum for VBScripting. Word VBA
and Microsoft Windows don't do Regular Expression natively and most people
in this forum just use the Word VBA wildcards to search within their
documents.

See this link for initial information on RegExp
http://tinyurl.com/2yb5o7

> I've got the following code in which I'm trying to use regular expressions:
>
[quoted text clipped - 16 lines]
> mark as not being a paragraph mark). Where am I going wrong? I thought the \n
> criteria was supposed to represent any type of line break.

Signature

Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID

Bryan - 08 Jun 2007 05:46 GMT
Thanks for the suggestion, Russ. For searching, I use wildcards also but I
would like to use regular expressions since they're better for evaluating
(not searching for) text so that I don't have to do something like

If Selection=chr(13) or selection=chr(10)

if I don't know if the end-of-line character will be a soft or hard break. I
would prefer to take advantage of pattern matching rather than a specific
character. I've never been successful, for example, in writing

if selection="^p"

but I use ^p all the time for searching. If you know of a better way for
evaluating a selection, I'll readily welcome the suggestion.

Signature

Bryan

> I believe you are using a VBScripting object to do regular expressions. You
> might find more help on that in a different forum for VBScripting. Word VBA
[quoted text clipped - 25 lines]
> > mark as not being a paragraph mark). Where am I going wrong? I thought the \n
> > criteria was supposed to represent any type of line break.
Russ - 08 Jun 2007 07:24 GMT
Here is more information on trying Regular Expressions in VBA:

http://www.j.nurick.dial.pipex.com/Code/index.htm

One downside is that they rely on VBScripting or Windows Scripting which
won't work in MacWord VBA.

> Thanks for the suggestion, Russ. For searching, I use wildcards also but I
> would like to use regular expressions since they're better for evaluating
[quoted text clipped - 10 lines]
> but I use ^p all the time for searching. If you know of a better way for
> evaluating a selection, I'll readily welcome the suggestion.

Signature

Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID

 
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.