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 / September 2007

Tip: Looking for answers? Try searching our database.

Need Macro Advice

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
douglascfast@hotmail.com - 12 Sep 2007 18:58 GMT
Hello all,

Need some advice / help

I need a macro in Word that will look for a sting /* and then find
another Sting */  and turn those strings and what is between them
Green.  I would use the same function for single quotes and turn what
is between them red.

I have the Keyword bit down thanks to some postings on the web.

I'm trying to color code my SQL code and my VBA code for print outs
(helps me read what is going on.

Any help would be great.

Thanks

Doug
m rafala - 12 Sep 2007 20:19 GMT
How about this:

Sub MakeGreen()
   Selection.Find.ClearFormatting
   Selection.Find.Replacement.ClearFormatting
   Selection.Find.Replacement.Font.ColorIndex = wdBrightGreen
   With Selection.Find
       .Text = "/*[!\/]/"
       .Replacement.Text = ""
       .Forward = True
       .Wrap = wdFindContinue
       .Format = True
       .MatchCase = False
       .MatchWholeWord = False
       .MatchAllWordForms = False
       .MatchSoundsLike = False
       .MatchWildcards = True
   End With
   Selection.Find.Execute Replace:=wdReplaceAll
End Sub

> Hello all,
>
[quoted text clipped - 15 lines]
>
> Doug
douglascfast@hotmail.com - 13 Sep 2007 00:47 GMT
What can I say?

EXCELLENT!

Here is what I did with it, for the three options.
1) /* */ Green comment
2) --   Green comment
3) 'aaa'  Red for literal's

Any ideas to make it better / faster / easier = or something I missed?

Love to learn and maybe someone else can use as well . . . .

Sub SQLComment()
 Selection.Find.ClearFormatting
 Selection.Find.Replacement.ClearFormatting
'    Selection.Find.Replacement.Font.Color = wdColorGreen

   With Selection.Find
       .Text = "/*[!\/]*/"
       .Replacement.Text = ""
       .Forward = True
       .Wrap = wdFindContinue
       .Replacement.Font.Color = wdColorGreen
       .Format = True
       .MatchCase = False
       .MatchWholeWord = False
       .MatchAllWordForms = False
       .MatchSoundsLike = False
       .MatchWildcards = True
   End With

   Selection.Find.Execute Replace:=wdReplaceAll

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting

   With Selection.Find
       .Text = "'[!\/]'"
       .Replacement.Text = ""
       .Forward = True
       .Wrap = wdFindContinue
       .Replacement.Font.Color = wdColorRed
       .Format = True
       .MatchCase = False
       .MatchWholeWord = False
       .MatchAllWordForms = False
       .MatchSoundsLike = False
       .MatchWildcards = True
   End With

   Selection.Find.Execute Replace:=wdReplaceAll

   Selection.Find.ClearFormatting
   Selection.Find.Replacement.ClearFormatting

   With Selection.Find
       .Text = "--**^13"
       .Replacement.Text = ""
       .Forward = True
       .Wrap = wdFindContinue
       .Replacement.Font.Color = wdColorBlue
       .Format = True
       .MatchCase = False
       .MatchWholeWord = False
       .MatchAllWordForms = False
       .MatchSoundsLike = False
       .MatchWildcards = True
   End With

   Selection.Find.Execute Replace:=wdReplaceAll
End Sub
m rafala - 13 Sep 2007 16:59 GMT
Hmmm...

What I typed is not quite what I intended.

Looks like I typed this:  .Text = "/*[!\/]/"
It's better off like this:  .Text = "/\*[!\/]@\*/"

which means essentially, find a slash, asterisk, a string of non-slashes,
asterisk, followed by a slash. The former works, but its not as precise (and
kind of pointless).

> What can I say?
>
[quoted text clipped - 68 lines]
>    Selection.Find.Execute Replace:=wdReplaceAll
> End Sub

Rate this thread:






 
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.