RE: Single quotes in OnAction property of a button

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Use replace and change one single quote to two single quotes

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

"Ray C" wrote:

I have VBA code that adds buttons to a work***. 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?

.


Quantcast