Display double quotes in text.

V

Vamsi.

Hi,

I am writing a Macro in Excel2003.
I have a variable x.

x = "ABC"

I want to dispay the text

Hello r u fine "ABC"

Note that ABC must be in double quotes.

When i give the following command i am getting error:

Hello r u fine & """ & x & """ --This doesn't work for
double quotes

Hello r u fine & "'" & x & "'" --This works for
displaying single quotes

Why is this so!!! how do i go about this??

Appreciate any help.

Vamsi.
 
R

Rob van Gelder

Whenever you want to enclose " in doublequotes, represent it as ""
x = "Hello r u fine ""ABC"""

or

x = "ABC"
MsgBox "Hello r u fine """ & x & """"


Please - do not use Chr(34) for this purpose - It's so nasty.
 
F

Frank Kabel

Rob said:
Whenever you want to enclose " in doublequotes, represent it as ""
x = "Hello r u fine ""ABC"""

or

x = "ABC"
MsgBox "Hello r u fine """ & x & """"


Please - do not use Chr(34) for this purpose - It's so nasty.

Hi Rob
why do you think this is nasty :)
IMHO especially beginners could have problems with double quotes

Frank
 
R

Rob van Gelder

MsgBox Chr(84) & Chr(114) & Chr(117) & Chr(115) & Chr(116) & Chr(32) & _
Chr(109) & Chr(101) & Chr(44) & Chr(32) & _
Chr(105) & Chr(116) & Chr(39) & Chr(115) & Chr(32) & _
Chr(110) & Chr(97) & Chr(115) & Chr(116) & Chr(121)

For the beginner, learning escape character concept is far more useful than
learning the Ascii table.
Escape characters are used in many programs.
 
F

Frank Kabel

Rob said:
MsgBox Chr(84) & Chr(114) & Chr(117) & Chr(115) & Chr(116) & Chr(32)
& _ Chr(109) & Chr(101) & Chr(44) & Chr(32) & _
Chr(105) & Chr(116) & Chr(39) & Chr(115) & Chr(32) & _
Chr(110) & Chr(97) & Chr(115) & Chr(116) & Chr(121)

For the beginner, learning escape character concept is far more
useful than learning the Ascii table.
Escape characters are used in many programs.
:)
o.k I'm convinced!

Frank
 
T

Tanner Dhesi

Hi - something along these lines should work - just need
more double quotes!

"Hello r u fine """"" & x & """"""

Tanner Dhesi
(e-mail address removed)
 
D

Dana DeLouis

I have seen some code that split the difference and written like this:

Dim s As String
Dim qq As String 'Double Quote
qq = Chr(34)
s = "Hello r u fine " & qq & "ABC" & qq
MsgBox s

I personally find this way a little easier to read and debug. To me, it is
a hair clearer that qq is in fact the Double Quote character.

One can also use characters a little higher on the asc chart if one's
situation allows.
Here, I often might use the double quotes from the Alt+0148 character.
(I don't think it will show here in the newsgroup posting).

s = "Hello r u fine "ABC" "

On a really complicated string about to be evaluated, I just cannot follow /
debug the many double quotes. By using 148, I find it much easier to read.
I will then run a final cleanup before evaluation by letting Excel do the
hard work.

s = Replace(s, Chr(148), Chr(34))


Just some thoughts. :>)
 
P

pmarino

QuoteQuote is understood as a quote mark within a string

So your code should be

Hello r u fine & """" & x & """"

that's four quote marks 1) open quote 2,3) quote inside a string 4
close quot
 

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