Translation of PC VBA code to MAC

A

alina b.

Hello,

I have the following code in my PC version that works without error,
could someone tell me how to modify it so that I can have it open in a
MAC version?


pathname = ActiveWorkbook.Path
Databasaefile = pathname & "\Database.XLS"
Workbooks.Open Filename:=Databasefile


Basically, for the third line it gives me a Run-time error. I believe
it doesn't recognize the pathname.


Thanks,
alina b.
 
J

Jim

Here's some code that often works for me.
Some adaptation is probably required.
Jim
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Code Snippet
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
txt = " Output File? - Yes/No "
YesNo = MsgBox(prompt:=txt, Title:="File Out?", Buttons:=vbYesNo)
If YesNo = vbYes Then
Call GetNewFileName(fout$, out$)
With Workbooks.Add
.SaveAs Filename:=fout$
outbook = .Name
outsheet = .ActiveSheet.Name
' Debug.Print outbook, outsheet
End With
Set output = Workbooks(outbook).Sheets(outsheet)
Workbooks(outbook).Sheets("Sheet2").Activate
End If
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Supporting Subs/Functs
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function MacOrPC(Path)
If Path = "" Then Path = CurDir()
' ' debug.Print Path
MacOrPC = "Mac"
nx = Len(Path)
For i = 1 To nx - 1
If Mid(Path, i, 2) = ":\" Then MacOrPC = "PC"
Next i
End Function

Sub GetNewFileName(File_name$, sName)
Select Case MacOrPC("")
Case "Mac"
sel = ":"
ff = "XSL8"
Case "PC"
sel = "\"
ff = "Excel (*.xls),*.xls"
End Select

File_name$ = Application.GetSaveAsFilename(Initialfilename:="New
file", FileFilter:=ff)
kout = 1

sName = File_name$
Do 'Get file short name
kn = InStr(sName, sel)
If kn <> 0 Then
sName = Mid(sName, kn + 1, Len(sName))
Else
Exit Do
End If
Loop
End Sub
 
J

Jim

Here's some code that often works for me.
Some adaptation is probably required.
Jim
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Code Snippet
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
txt = " Output File? - Yes/No "
YesNo = MsgBox(prompt:=txt, Title:="File Out?", Buttons:=vbYesNo)
If YesNo = vbYes Then
Call GetNewFileName(fout$, out$)
With Workbooks.Add
.SaveAs Filename:=fout$
outbook = .Name
outsheet = .ActiveSheet.Name
' Debug.Print outbook, outsheet
End With
Set output = Workbooks(outbook).Sheets(outsheet)
Workbooks(outbook).Sheets("Sheet2").Activate
End If
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Supporting Subs/Functs
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function MacOrPC(Path)
If Path = "" Then Path = CurDir()
' ' debug.Print Path
MacOrPC = "Mac"
nx = Len(Path)
For i = 1 To nx - 1
If Mid(Path, i, 2) = ":\" Then MacOrPC = "PC"
Next i
End Function

Sub GetNewFileName(File_name$, sName)
Select Case MacOrPC("")
Case "Mac"
sel = ":"
ff = "XSL8"
Case "PC"
sel = "\"
ff = "Excel (*.xls),*.xls"
End Select

File_name$ = Application.GetSaveAsFilename(Initialfilename:="New
file", FileFilter:=ff)
kout = 1

sName = File_name$
Do 'Get file short name
kn = InStr(sName, sel)
If kn <> 0 Then
sName = Mid(sName, kn + 1, Len(sName))
Else
Exit Do
End If
Loop
End Sub
 
B

Bob Greenblatt

Hello,

I have the following code in my PC version that works without error,
could someone tell me how to modify it so that I can have it open in a
MAC version?


pathname = ActiveWorkbook.Path
Databasaefile = pathname & "\Database.XLS"
Workbooks.Open Filename:=Databasefile


Basically, for the third line it gives me a Run-time error. I believe
it doesn't recognize the pathname.


Thanks,
alina b.
I did not even look at Jims' elaborate solution he just posted. All you have
to do is change the second line to the following:
Databasefile = pathname & application.pathseparator & "Database.xls"

(Is databasefile really spelled databasaefile as in the posted code?)

This will allow the code to work on either platform.
However, I'll bet a small sum that this is not the only problem, just the
first you'll find. Keep posting here and we'll try to help.
 

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