Target specific characters for a font change (color)

B

Bill

Hi I have some repetitive output which looks like this:

DROP TABLE "CMF" CASCADE CONSTRAINTS;
CREATE TABLE "CMF" ("DUNS_NUMBER" VARCHAR2(4000) ,
"CUSTOMER_NAME" VARCHAR2(4000) ,
"DNB_TRADE_STYLE" VARCHAR2(4000) ,


What I need is two classes of search within a line, and then to
colorize accordingly using (I presume) book marks, or if this can be
done on a character-by-character basis from a given depth within the
line, so much the better.

First search: Find the first open parenthesis and double-quote
combination on a line which contains the words "CREATE TABLE", and
colorize as RED everything from thereafter, up to the very next double-
quote.

Second Search: If the line does not contain "CREATE TABLE", colorize
everything between the first and second double-coutes.
 
E

Ed Weber

Try this macro whch will work for both straight and curly double-quotes..
Click on the desired line - there is no need to select anything - then run
the macro.


Sub ColorizeQuotedText()
'by Ed Weber
Dim strQuotes As String
Dim rng As Range
'Include both straight and curly quotes
strQuotes = "[" & Chr(34) & Chr(147) & Chr(148) & "]"
Set rng = ActiveDocument.Bookmarks("\Line").Range
If InStr(rng.Text, "CREATE TABLE") > 0 Then
With rng.Find
.MatchWildcards = True
.ClearFormatting
.Text = "\(" & strQuotes & "*" & strQuotes
.Execute
rng.Start = rng.Start + 2
rng.End = rng.End - 1
End With
Else
With rng.Find
.MatchWildcards = True
.ClearFormatting
.Text = strQuotes & "*" & strQuotes
.Execute
rng.Start = rng.Start + 1
rng.End = rng.End - 1
End With
End If
If rng.Find.Found Then rng.Font.ColorIndex = wdRed
End Sub

--


Bill said:
Hi I have some repetitive output which looks like this:

DROP TABLE "CMF" CASCADE CONSTRAINTS;
CREATE TABLE "CMF" ("DUNS_NUMBER" VARCHAR2(4000) ,
"CUSTOMER_NAME" VARCHAR2(4000) ,
"DNB_TRADE_STYLE" VARCHAR2(4000) ,


What I need is two classes of search within a line, and then to
colorize accordingly using (I presume) book marks, or if this can be
done on a character-by-character basis from a given depth within the
line, so much the better.

First search: Find the first open parenthesis and double-quote
combination on a line which contains the words "CREATE TABLE", and
colorize as RED everything from thereafter, up to the very next double-
quote.

Second Search: If the line does not contain "CREATE TABLE", colorize
everything between the first and second double-coutes.




---
avast! Antivirus: Outbound message clean.
Virus Database (VPS): 120605-0, 06/05/2012
Tested on: 6/5/2012 10:26:39 AM
avast! - copyright (c) 1988-2012 AVAST Software.
http://www.avast.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top