Does anybody know if Excel has an escape character equivalent to the \ in C?
I want to pass a string with a " in it to a user defined function but Excel refused to pass any strings containing a " such as =MyFun("He said "hello"").
In C I can use \" to specifiy a " within a string but is there any way to do this in Excel? Thanks
string escape character
-
-
-
Does this work:
=MyFun("He said ""Hello""")
-
better still use teh ASCII - Chr(34)
-
Thanks for all your help, but are there any other escape characters that I could use other than " because "" is more confusing than \".
-
I think the only 2 options have been provided here.
-
Hi,
A couple more examples. The first one is possibly even higher on the confusion scale
The second one, using a constant, is probably about as close as you are going to get to your original request (but you can't use \ as the constant - pick something else)
[vba]Sub Test()MsgBox "He said " & """" & "Hello" & """"
End SubSub Test2()
Const qts As String = """"
MsgBox "He said " & qts & "Hello" & qts
End Sub[/vba] -
Thank you for all your help. I think I'll just stick to "".
Josh
-
-
Re: string escape character
... 9 years later
The 'Escape' character in the title is a little misleading. The OP wants to embed a " character in a string using VBA and the original replies address that.
The tilde is used in Excel when, for example, using Find/Replace. It is an Escape character to indicate the next character should be interpreted literal - to find a '*', you'd use '~*', as an example.
Participate now!
Don’t have an account yet? Register yourself now and be a part of our community!