+ Reply to Thread
Results 1 to 7 of 7

Application.Run - Spaces and single quotes

  1. #1
    Forum Contributor
    Join Date
    02-23-2006
    Location
    Near London, England
    MS-Off Ver
    Office 2003
    Posts
    770

    Question Application.Run - Spaces and single quotes

    Ok so I know I can run a function in another (open) workbook by doing the following line:

    Please Login or Register  to view this content.
    I'm also aware that if the workbook name contains spaces it must be wrapped in single quotes, thus:

    Please Login or Register  to view this content.
    My question is, how do I cope with it if the workbook name has spaces AND single quotes in the name? The single quote in the name effectively 'ends' the single quotes that are supposed to wrap the name, and I cannot see how I can escape the single quote character so that VBA realises it is part of the name, and not a delimiter.

    Please Login or Register  to view this content.
    Any ideas please? (Changing the target workbook name is not really an option as the workbooks are auto-named from elsewhere based on some input data).

    Thanks!
    Last edited by Phil_V; 06-03-2009 at 05:35 AM. Reason: Making code clearer with colour :)
    If you find the response helpful please click the scales in the blue bar above and rate it
    If you don't like the response, don't bother with the scales, they are not for you

  2. #2
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Smile Re: Application.Run - Spaces and single quotes

    Good morning Phil_V
    Quote Originally Posted by Phil_V View Post
    My question is, how do I cope with it if the workbook name has spaces AND single quotes in the name?
    Untested, but try forcing the ' into the variable by calling it using its Char number (which is 39), thus :
    Please Login or Register  to view this content.
    HTH

    DominicB
    Please familiarise yourself with the rules before posting. You can find them here.

  3. #3
    Forum Contributor
    Join Date
    02-23-2006
    Location
    Near London, England
    MS-Off Ver
    Office 2003
    Posts
    770

    Re: Application.Run - Spaces and single quotes

    Thanks, but alas no, the wrkbookname string just ends up formed exactly as if I had typed the character in

  4. #4
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Application.Run - Spaces and single quotes

    You need to double up the apostrophe in the file name in the Run statement. For example:
    Please Login or Register  to view this content.
    Remember what the dormouse said
    Feed your head

  5. #5
    Forum Contributor
    Join Date
    02-23-2006
    Location
    Near London, England
    MS-Off Ver
    Office 2003
    Posts
    770

    Re: Application.Run - Spaces and single quotes

    Excellent, works like a dream

    Thanks for that!

  6. #6
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Application.Run - Spaces and single quotes

    Glad to help.
    Incidentally, a good way to figure out the syntax is to create a simple test macro in the workbook (with no parameters), switch to any other workbook, then bring up the macro dialog - it should list the macro in the form that application.run needs it.

  7. #7
    Forum Contributor
    Join Date
    02-23-2006
    Location
    Near London, England
    MS-Off Ver
    Office 2003
    Posts
    770

    Re: Application.Run - Spaces and single quotes

    Nice tip that, thanks

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1