Why do we need Application.PathSeparator?
Asked Answered
P

4

5

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)

Platelet answered 25/4, 2018 at 2:38 Comment(6)
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..Ocieock
it's your your lucky day: Application.International (xlListSeparator)Platelet
I guess you don't recall back when the Mac path separator was :Quaint
I still have a machine which returns in some cases a path with : on a macCaruso
@Caruso 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...Platelet
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 #48693911Caruso
P
6

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.

Penner answered 27/1, 2020 at 16:25 Comment(2)
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.Platelet
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.Penner
S
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...

Spoon answered 7/8, 2019 at 16:6 Comment(0)
E
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).

Ensor answered 4/7, 2021 at 17:54 Comment(1)
Does Application.PathSeparator reflect this?Splashdown
N
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.

Neff answered 5/8, 2022 at 11:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.