putting italics on text in quotes

C

cw

Hi all

Hopefully this is not as dumb as my last post, but I am trying to find a way to format any text that appears in quote marks to italic text "hi" to "hi"

is this possible

Craig
 
G

Greg Maxey

Yes it is possible:

Sub ScratchMacro()
'Italicizes text exclusive of the quotes marks
Dim oRng As Range
Set oRng = ActiveDocument.Content
With oRng.Find
.ClearFormatting
.Text = """<*>"""
.Forward = True
.Wrap = wdFindStop
.MatchWildcards = True
Do While .Execute
With oRng
.MoveEnd Unit:=wdCharacter, Count:=-1
.MoveStart Unit:=wdCharacter, Count:=1
.Font.Italic = True
.Collapse wdCollapseEnd
End With
Loop
End With
End Sub
 
C

cw

You are a legend

thanks

Craig


Greg Maxey said:
Yes it is possible:

Sub ScratchMacro()
'Italicizes text exclusive of the quotes marks
Dim oRng As Range
Set oRng = ActiveDocument.Content
With oRng.Find
.ClearFormatting
.Text = """<*>"""
.Forward = True
.Wrap = wdFindStop
.MatchWildcards = True
Do While .Execute
With oRng
.MoveEnd Unit:=wdCharacter, Count:=-1
.MoveStart Unit:=wdCharacter, Count:=1
.Font.Italic = True
.Collapse wdCollapseEnd
End With
Loop
End With
End Sub
 
C

cw

Almost perfect

its not working

I am currently working through with the debugger

and it is getting to this point and then jumping to the end

~~~>>> Do While .Execute
With oRng
.MoveEnd Unit:=wdCharacter, Count:=-1
.MoveStart Unit:=wdCharacter, Count:=1
.Font.Italic = True
.Collapse wdCollapseEnd
End With
Loop
End With


not an expert with vba so i am not sure why any help would be greatly
appreciated

thanks
 
G

Greg Maxey

Would you by chance be using those goofey little curley quotes? Try:

.Text = Chr(147) & "<*>" & Chr(148)
 
C

cw

Quite a possibility

I will give it a try today and let you know
thanks for your help, much appreciated

Craig
 
C

cw

Quite a possibility

I will give it a try today and let you know
thanks for your help, much appreciated

Craig
 
C

cw

got it!!

Nice one

it was skipping a few out still after I changed that code to your last
message

but I noticed that it was skipping the ones with a full stop at the end

"hi." rather than "hi"

so I just copied the code and changed the new line to

.Text = Chr(147) & "<*>." & Chr(148)

added the full stop

it runs through it twice now but you barely notice the time difference

so its all cool

thanks very much for your help
Craig
 

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