Single quotes in OnAction property of a button

R

Ray C

I have VBA code that adds buttons to a worksheet. In one instance I add a
button and I assign a macro whereby it opens Windows Explorer to that file:

..OnAction = "'OpenExplorer """ & strMyFileName & """'"

The problem I have is that some files have apostrophe's in the file name.
And seeing that I need to put the OnAction property inside double-quotes and
the macro itself inside single quotes, I have a problem. Whenever a file has
a single quote in its name the code gives me an error.

Any suggestions?
 
J

Joel

Use replace and change one single quote to two single quotes

strMyFileName = replace(strMyFileName,"'","''")
 

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