4

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)

eirikdaude
  • 3,106
  • 6
  • 25
  • 50
ashleedawg
  • 20,365
  • 9
  • 72
  • 105
  • 1
    I've wondered the same thing; especially so since the powers-that-be decided it wasn't important to include an Application.ListSeparator property in the Application object's members which to my mind would have been very useful.. –  Apr 25 '18 at 03:09
  • 2
    it's your your lucky day: [**`Application.International (xlListSeparator)`**](https://msdn.microsoft.com/en-us/vba/excel-vba/articles/application-international-property-excel) – ashleedawg Apr 25 '18 at 03:34
  • 10
    I guess you don't recall back when the Mac path separator was `:` – Tim Williams Apr 25 '18 at 03:47
  • 2
    I still have a machine which returns in some cases a path with : on a mac – QHarr Apr 25 '18 at 04:46
  • @QHarr So it's still running the *original* Mac OS?! Does VBA and/or Office ever run on this machines? That would confirm my suspicion of backwards compatibility being the reason we still need it... – ashleedawg Apr 25 '18 at 05:46
  • 3
    It is a 2011 Mac but the OS is up to date (so presumably actually slighter older than that). I discovered it as a problem regarding HDD with answering this https://stackoverflow.com/questions/48693411/error-53-when-opening-csv-file-on-mac – QHarr Apr 25 '18 at 06:03

4 Answers4

3

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.

chris neilsen
  • 52,446
  • 10
  • 84
  • 123
barbecue
  • 157
  • 9
  • not sure how I missed that. My question even included a link to the relevant wiki. Perhaps my thinking was confused because `/` can actually be used on both platforms, although it's technically not right for Windows. – ashleedawg Jun 24 '21 at 16:02
  • 2
    Trying to write scripts that work with paths from both platforms is a nightmare. I wish Microsoft had gone with the forward slash like all the cool kids did. – barbecue Jun 24 '21 at 21:22
1

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

0

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

gbo
  • 1
0

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.

robotik
  • 1,837
  • 1
  • 20
  • 26