VB Compatibility Issues with Mac

Breader11

New Member
Joined
Sep 23, 2012
Messages
6
I have a question about compatibility of VBA code between the PC and Mac. I have several scripts that I am using successfully on my PC at work, but when I try to run them on Excel 2011 on my Mac at home, they error out. I'm assuming this is a Mac issue, and not an issue with compatibility between two different editions of Excel. Below is one example.


PC VB Code:

Sub RenameSheets()
Dim MyFolder As String
Dim MyFile As String
Dim wbname As String
MyFolder = "C:\Users\breader\Desktop\<wbr>Test\aaCompletedWorkbooks"
MyFile = Dir(MyFolder & "\*.xls")
Application.ScreenUpdating = False
Do While MyFile <> ""
Workbooks.Open FileName:=MyFolder & "\" & MyFile
With ActiveWorkbook
wbname = Left(.Name, InStr(.Name, ".") - 1)
.Sheets(1).Name = wbname
.Close savechanges:=True
End With
MyFile = Dir
Loop
Application.ScreenUpdating = True
End Sub




Error on Excel 2011 on MAC (error in red):

Sub RenameSheets()
Dim MyFolder As String
Dim MyFile As String
Dim wbname As String
MyFolder = "/Users/appleuser/Desktop/<wbr>DatabaseCreation"
MyFile = Dir(MyFolder & "\*.xls")
Application.ScreenUpdating = False
Do While MyFile <> ""
Workbooks.Open FileName:=MyFolder & "\" & MyFile
With ActiveWorkbook
wbname = Left(.Name, InStr(.Name, ".") - 1)
.Sheets(1).Name = wbname
.Close savechanges:=True
End With
MyFile = Dir
Loop
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Hi, :)

MAC has no backslash (\) or slash (/), but the colon (:) as a separator in the path such as:

Code:
Workbooks.Open Filename:="Users:Appleuser:Downloads:Sample.xls"
 
Upvote 0
I have a question about compatibility of VBA code between the PC and Mac. I have several scripts that I am using successfully on my PC at work, but when I try to run them on Excel 2011 on my Mac at home, they error out. I'm assuming this is a Mac issue, and not an issue with compatibility between two different editions of Excel. Below is one example.

Your specific question has been answered but thought I'd add that the Mac versions of Excel did/do run different versions of VBA than the PC versions so platform and version compatibility are two stumbling blocks you're likely to run into.

I don't know if it applies to the latest Mac versions but previously they were bundled with VBA5 where as the PC versions were VBA6 and now VBA7 (meaning native VBA6 functions would not work on the Mac).

You can use conditional compilation to achieve cross platform compatibility. Something I'm using more and more thanks to differences between 32 bit and 64 bit office. The whole family of products is becoming less and less interoperable over time!

Conditional compilation works like this

Code:
#If MAC then
       'Mac Stuff here
#Else
       'PC Stuff here
#End If

Note the # character. That tells VBA to only compile the code if the condition is met.
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,917
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top