Why do we need Application.PathSeparator?

5.9k Views Asked by At

MS Office VBA has a property called Application.PathSeparator.

I'm supportive of interoperability, but Office runs only on Windows & MacOS, and both platforms use the same \ path separator.

When would it ever be advisable to use Application.PathSeparator (as opposed to simply hardcoding the \ and saving 22 keystrokes)?


To be clear, I do think it's important to support international differences when posting code on an international site like Stack Overflow, so I will often use Application.International properties such as xlDateSeparator and, more importantly, xlDateOrder. (More about those here)

4

There are 4 best solutions below

0
Andreas Katits On

In some cases it's even not a great idea to use Application.PathSeparator, because if you open a workbook from a network space, e.g. a OneDrive out of a browser, the correct separator would be /. Anyway, Application.PathSeparator doesn't notice that...

2
barbecue On

This question is based on an incorrect assumption, that both Mac OS and Windows use the same path separator character. That is incorrect.

Mac OS X does not use the backslash (\) as a path separator. It uses the forward slash (/) like other Unixlike operating systems. In the Mac OS command line, the backslash acts like an escape character, so using the same character in both platforms could cause unexpected results.

1
gbo On

I know that for some company/file-sharing app, the path separator on a shared drive is "/" instead of "". I have seen that very recently (in 2021).

0
robotik On

Other answers suggest that Mac OS X uses the forward slash / as well as shared / network drives on Windows (that is not reflected in Application.PathSeparator).

So guess what, I used forward slash "/" instead of Application.PathSeparator in my VBA code for creating folder and opening file for output, and it worked just fine under Windows.