Macro not compatablie with Macs

vmackey

New Member
Joined
Jun 4, 2019
Messages
6
Hello, unfortunately I have a client that insists on using Macs. The Macro I am using below is returning a 1004 error for Method 'GetOpenFileame'_Application' failed when using a Mac only. Is there any way to correct to have it work on both Mac and PC?

Code:
Sub MergeExcelFiles()
    Dim fnameList, fnameCurFile As Variant
    Dim countFiles, countSheets As Integer
    Dim wksCurSheet As Worksheet
    Dim wbkCurBook, wbkSrcBook As Workbook
 
    fnameList = Application.GetOpenFilename(FileFilter:="Microsoft Excel Workbooks (*.xls;*.xlsx;*.xlsm),*.xls;*.xlsx;*.xlsm", Title:="Choose Excel files to merge", MultiSelect:=True)
 
    If (vbBoolean <> VarType(fnameList)) Then
 
        If (UBound(fnameList) > 0) Then
            countFiles = 0
            countSheets = 0
 
            Application.ScreenUpdating = False
            Application.Calculation = xlCalculationManual
 
            Set wbkCurBook = ActiveWorkbook
 
            For Each fnameCurFile In fnameList
                countFiles = countFiles + 1
 
                Set wbkSrcBook = Workbooks.Open(Filename:=fnameCurFile)
 
                For Each wksCurSheet In wbkSrcBook.Sheets
                    countSheets = countSheets + 1
                    wksCurSheet.Copy after:=wbkCurBook.Sheets(wbkCurBook.Sheets.Count)
                Next
 
                wbkSrcBook.Close SaveChanges:=False
 
            Next
 
            Application.ScreenUpdating = True
            Application.Calculation = xlCalculationAutomatic
 
            MsgBox "Processed " & countFiles & " files" & vbCrLf & "Merged " & countSheets & " worksheets", Title:="Merge Excel files"
        End If
 
    Else
        MsgBox "No files selected", Title:="Merge Excel files"
    End If
End Sub
Correction : The error message is :
Method 'GetOpenFilename'_Application'
 
Last edited by a moderator:

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Use Application.OperatingSystem to identify OS and use code depending on result.
 
Upvote 0
Use Application.OperatingSystem to identify OS and use code depending on result.


Apologies for misunderstanding, as I am not very familiar with VBA coding. How would I update the VBA code below to have it work?
 
Upvote 0
I'm assumed since you posted some code =), since I don't have a Mac it's difficult for me to verify the code and I can only give you some pointers. In the link below you should be able to find the solution for GetOpenFilename with Mac.
https://www.rondebruin.nl/mac/mac015.htm

With these two macros you can find out what OS you are running and run different code depending on.
Code:
Sub OS()
 Msgbox Application.OperatingSystem
End Sub
Sub Windows()
 Dim pos As Integer
 pos = InStr(Application.OperatingSystem, "Windows")
 If pos > 0 Then
   MsgBox "It's a Window!"
   'Replace Msgbox line with your code
 End if
 pos = InStr(Application.OperatingSystem, "Macintosh")
 If pos > 0 Then
  MsgBox "It's a Mac!"
   'Replace Msgbox line with your code
 End if
End Sub
 
Upvote 0
It's easier to use conditional compilation, in my opinion:

Rich (BB code):
#If Mac then
' do Mac things
#Else 
' do Windows things
#End  If
 
Upvote 0

Forum statistics

Threads
1,213,524
Messages
6,114,117
Members
448,549
Latest member
brianhfield

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