Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default 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?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default 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?

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
passing parameters to function assigned to button property onAction?? Matthew Dodds Excel Programming 0 October 13th 06 03:45 PM
Problem with Button OnAction property... fausto Excel Programming 2 February 26th 05 07:50 AM
Button Selection OnAction property Grant Reid Excel Programming 7 June 26th 04 03:39 AM
Find OnAction property Kemosabe Excel Programming 1 November 21st 03 03:34 PM


All times are GMT +1. The time now is 10:13 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"