ashleedawg
ashleedawg

Reputation: 21639

Why do we need Application.PathSeparator?

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)

Upvotes: 5

Views: 6608

Answers (4)

gbo
gbo

Reputation: 1

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

Upvotes: 0

robotik
robotik

Reputation: 2007

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.

Upvotes: 0

barbecue
barbecue

Reputation: 208

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.

Upvotes: 7

Andreas Katits
Andreas Katits

Reputation: 11

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...

Upvotes: 1

Related Questions