Mac equivilent VBA syntax

J

Jim May

In a Macro (written originally on my PC Windows) I have as line 2:

Const sPath = "C:\My Documents\Projects\Temp\"

My client has created on his office MAC -
The Folder Project and Subfolder Temp and placed
The appropriate files therein.

While there a few days ago when I tried either saving the file/macro or
either running it, not sure which now, I got an error message with
Pop-up referring to the Path Structure being incorrect and displaying
something like what it was expecting (showing)..

Macintosh:HD:Company Name, Inc:NotSureWhatElse:MaybeProjects:Temp <<<

My only question is how can I find the exact syntax I need (from the
MAC) to
Replace my line 2 above, so that both the macro will run and my file
will save?

Help Much appreciated, IN ADVANCE!
 
J

JE McGimpsey

My only question is how can I find the exact syntax I need (from the
MAC) to Replace my line 2 above, so that both the macro will run and
my file will save?

This really has little to do with VBA syntax. It's more a matter of
knowing how Mac OS paths work.

This is also a problem with hard-coding paths - it would cause you to
have to change the macro if you move to another PC, too, unless it had
the exact same path structure (which, admittedly, is more common on a PC
where volumes can't be renamed).

The easiest way to determine the path is to Cmd-click on the file's
titlebar to see the hierarchy of folders it resides in. You could also
record a macro that does a SaveAs on a workbook to the desired folder.
Look at the recorded macro's FileName argument for the SaveAs method.

The new hard coding will, of course, fail if the user changes the hard
drive name or creates a new user account.

A more robust method that I use regularly is, when first starting an
application, to get the path to the user's current home folder with
MacScript:

Dim sHomePath As String
Dim sDocsPath As String
sHomePath = MacScript("(path to home folder as string)")
sDocsPath = MacScript("(path to documents folder as string)")

then create the appropriate folder(s) within the home or documents
folders. I then save that path to the registry or (my preference) a text
file in the

~:Library:Application Support:

folder (where ~ is the user's home folder). On subsequent startups of my
app, the app looks for the registry or text file entry and verifies that
the folders/files exist. If not, the app asks the user to designate the
appropriate folder.
 
J

Jim

Try this:
Open an excel document in the folder of interest, (this sets the
current directory) then run the following code:

Sub get_path()
Path = CurDir()
Debug.Print "mac path is: "; Path
Debug.Print "doc path is: ", Path & ":mydoc.xls"
End Sub

CHECK the dir function in HELP. dir() returns paths.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top