0

I was trying to use the code from the following post to determine whether a different excel file is open:

Detect whether Excel workbook is already open

but my code was errorring out every time. After a bit of testing, I determined it appears to be because I have spaces in the filename/path. Is there a way to allow for the file path to include spaces?

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83

1 Answers1

0

You need to wrap the whole path and filename in double quotes if you have spaces in your file name.

So if you have a vba path & file name of:

WBPath = WB.Path & Application.PathSeparator & WBName

You need to add double quotes to the beginning and end of the string.

WBPath = """" & WB.Path & Application.PathSeparator & WBName & """"

What is """"? (The string starts with a " then the next two " " resolve to be a single double quote of text, then the last " ends the string.)

So you are in essence concatenating a Double Quote to the front of the path\file name and to the end.

Hope that helps. :)

abraxascarab
  • 661
  • 1
  • 6
  • 13