none
How to put single quotes around a workbook name RRS feed

  • Question

  • I'm opening a bunch of workbooks like such:

    Set wb = Workbooks.Open(Filename:=myPath & myFile)

    I need to run Macros in all of these workbooks.  The problem is, all these workbooks have spaces in their names, so I want to put single quotes around the workbook names.  I can't seem to get it working.

            wb = "'" & wb & "'"
            Application.Run (wb & "!Load_To_DB")

    I get error messages like 'can't assign to read-only property' and 'object doesn't support this property or method'.

    TIA


    Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.


    • Edited by ryguy72 Thursday, December 3, 2015 9:46 PM
    Thursday, December 3, 2015 9:34 PM

Answers

  • You shouldn't try to change the name of the workbook (that's what wb.Name = ... does).

    Does this work? (I haven't tested it)

        Application.Run "'" & wb,Name & "'!Load_To_DB"


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    • Marked as answer by ryguy72 Thursday, December 3, 2015 10:26 PM
    Thursday, December 3, 2015 9:49 PM

All replies

  • You shouldn't try to change the name of the workbook (that's what wb.Name = ... does).

    Does this work? (I haven't tested it)

        Application.Run "'" & wb,Name & "'!Load_To_DB"


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    • Marked as answer by ryguy72 Thursday, December 3, 2015 10:26 PM
    Thursday, December 3, 2015 9:49 PM
  • Ha.  I knew it was something like that.  I got my quotes wrong, and then went down a rabbit hole.  Thanks for helping me get this straightened out Hans!!


    Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.

    Thursday, December 3, 2015 10:26 PM