ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Single quotes in OnAction property of a button (https://www.excelbanter.com/excel-programming/408943-single-quotes-onaction-property-button.html)

Ray C

Single quotes in OnAction property of a button
 
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?


joel

Single quotes in OnAction property of a button
 
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 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?



All times are GMT +1. The time now is 12:19 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com