Bernard REY said:
Bob Greenblatt wrote :
That'll give you a *precise* description of the OS (ie "Macintosh (PowerPC)
10.32"). It may be quite useful to simply test the Path Separator, in order
to use one code line or another, depending upon the result. Here's a couple
of lines I often use when writing some cross-platform macro:
MySep = Application.PathSeparator
If MySep = "\" Then
MyFilePath = "C:\My documents\Excel"
ElseIf MySep = ":" Then
MyFilePath = "Macintosh HD
ocuments:Excel"
Else
MyMessage = MsgBox("Neither Mac, nor Windows, where are we now?", _
vbOK, "Unidentified OS!")
Exit Sub
End If
Just to take this a little further - why do you want to know whether the
user is on a Mac or a PC? If it's to run code differently, depending on
the platform, then you can use conditional compiliation to let the
compiler take care of it. The advantage to this approach is that you can
conditionally compile so that the test is done at compile-time, not at
run-time. For instance, the GetOpenFileName syntax is different between
PC's and Macs, but this syntax will include either PC or Mac code in the
run-time execution:
Dim result As String
#If Mac Then
result = Application.GetOpenFilename (_
FileFilter:="TEXT", _
ButtonName:="Choose")
#Else
result = Application.GetOpenFilename( _
FileFilter:="Text Files (*.txt), *.txt")
#End If
If result = "" Then Exit Sub
If the code is run on a Mac, this will be in the run-time code:
Dim result As String
result = Application.GetOpenFilename (_
FileFilter:="TEXT", _
ButtonName:="Choose")
If result = "" Then Exit Sub
Otherwise this will be in the run-time code:
Dim result As String
result = Application.GetOpenFilename( _
FileFilter:="Text Files (*.txt), *.txt")
If result = "" Then Exit Sub
Note that if the code if executed many times, this is much faster than
doing tests at run time to take one branch or another since the platform
determination only had to be done once.