Macro/Word converting double-quote marks into angle quotation marks

S

supersub15

Hi all,

I've scripted a vba macro that opens html pages in txt format and adds
the following line after <BODY> (through a search and replace):

<link rel="stylesheet" type="text/css" href="Output.css" />

The problem I'm having is that Word or the macro (don't really know)
is converting the double-quote marks into angled quotation marks
(ASCII 147 and 148), which makes the line above unreadable by the
browser.

I've tried using Chr(34):
"<BODY><link rel=" & Chr(34) & "stylesheet" & Chr(34) & " type=" & Chr
(34) & "text/css" & Chr(34) & " href=" & Chr(34) & "Output.css" & Chr
(34) & " />"

But the browser still can't read it for some reason. I manually copied
the line from a working file, and they look exactly the same, except
that the copied line is recognized by the browser and the line added
by the macro is not.

Any ideas?

Thanks
Carlos
 
J

Jay Freedman

Hi Carlos,

It would be better to avoid the whole issue by never getting the ASCII
147 and 148 quotes in the first place. They're inserted by the
'"Straight quotes" with "smart quotes"' option under Tools >
AutoCorrect Options > AutoFormat As You Type. On any particular
instance of Word that option may be on or off, so your problem may
appear for some users and not others.

To work around it, in your macro that adds the stylesheet link, do
this:

Dim userSmartQutes As Boolean
userSmartQuotes = Options.AutoFormatAsYouTypeReplaceQuotes
Options.AutoFormatAsYouTypeReplaceQuotes = False

' do your work here -- all will be straight quotes (Chr(34))

' restore user's setting
Options.AutoFormatAsYouTypeReplaceQuotes = userSmartQuotes

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 

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