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:

most

Board Regular
Joined
Feb 22, 2011
Messages
83
Platform
Windows, Mobile
Use Application.OperatingSystem to identify OS and use code depending on result.
 

vmackey

New Member
Joined
Jun 4, 2019
Messages
6
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?
 

most

Board Regular
Joined
Feb 22, 2011
Messages
83
Platform
Windows, Mobile
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
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
34,618
Office Version
365, 2019, 2016, 2010
Platform
Windows, MacOS
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
 

Forum statistics

Threads
1,086,092
Messages
5,387,787
Members
402,076
Latest member
MotoMoto

Some videos you may like

This Week's Hot Topics

Top