'Run-time error '1004': Method 'GetOpenFilename' of object '_Application' failed' on MacOs

%3CLINGO-SUB%20id%3D%22lingo-sub-3065508%22%20slang%3D%22en-US%22%3E'Run-time%20error%20'1004'%3A%20Method%20'GetOpenFilename'%20of%20object%20'_Application'%20failed'%20on%20MacOs%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3065508%22%20slang%3D%22en-US%22%3E%3CP%3EGreetings!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI'm%20writing%20some%20VBA%20code%20for%20selecting%20a%20specified%20file%20in%20order%20to%20retrieve%20info%20from%20it%20and%20paste%20into%20destination.%20I%20use%26nbsp%3BGetOpenFilename%20method%2C%20however%20on%20running%20I%20get%20the%20above%20mentioned%20error%26nbsp%3B'Run-time%20error%20'1004'%3A%20Method%20'GetOpenFilename'%20of%20object%20'_Application'%20failed'.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHere%20is%20my%20code%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3ESub%20importData()%0A%20%20%20%20Dim%20fileToOpen%20As%20Variant%0A%20%20%20%20Dim%20wbImportFile%20As%20Workbook%0A%20%20%20%20fileToOpen%20%3D%20Application.GetOpenFilename(Title%3A%3D%22Specify%20folder%20with%20source%20file%22%2C%20filefilter%3A%3D%22Excel%20Files(*.xls*)%2C%20*xls*%22)%0A%0A%20%20%20%20If%20fileToOpen%20%26lt%3B%26gt%3B%20False%20Then%0A%20%20%20%20%20%20%20%20Set%20wbImportFile%20%3D%20Workbooks.Open(fileToOpen)%0A%20%20%20%20%20%20%20%20wbImportFile.Worksheets(%22Sheet1%22).Range(%22C3%3AM4%22).Copy%0A%20%20%20%20%20%20%20%20ThisWorkbook.Worksheets(%22Sheet1%22).Range(%22B3%22).PasteSpecial%20(xlPasteAll)%0A%20%20%20%20End%20If%0A%20%20%20%20%0AEnd%20Sub%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIt%20seems%20like%20this%20parameter%20causes%20an%20error%20%22filefilter%3A%3D%22Excel%20Files(*.xls*)%2C%20*xls*%22.%20This%20problem%20happens%20only%20on%20Mac.%20There%20is%20no%20problems%20with%20Windows%20version%20of%20Excel.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EDo%20you%20know%20when%20Microsoft%20will%20fix%20this%3F%3C%2FP%3E%3CP%3EThanks.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-3065508%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%20on%20Mac%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3120869%22%20slang%3D%22en-US%22%3ERe%3A%20'Run-time%20error%20'1004'%3A%20Method%20'GetOpenFilename'%20of%20object%20'_Application'%20failed'%20on%20MacOs%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3120869%22%20slang%3D%22en-US%22%3E%3CP%3EI%20have%20the%20same%20problem%2C%20I%20had%20to%20run%20Excel%20in%20a%20Windows%20VM%20on%20my%20MAC%20to%20solve%20it.....%20there're%20other%20problems%20too%20with%20Excel%20for%20MacOS%2C%20data%20segmentation%20problems...%3C%2FP%3E%3C%2FLINGO-BODY%3E
New Contributor

Greetings!

 

I'm writing some VBA code for selecting a specified file in order to retrieve info from it and paste into destination. I use GetOpenFilename method, however on running I get the above mentioned error 'Run-time error '1004': Method 'GetOpenFilename' of object '_Application' failed'.

 

Here is my code:

 

Sub importData()
    Dim fileToOpen As Variant
    Dim wbImportFile As Workbook
    fileToOpen = Application.GetOpenFilename(Title:="Specify folder with source file", filefilter:="Excel Files(*.xls*), *xls*")

    If fileToOpen <> False Then
        Set wbImportFile = Workbooks.Open(fileToOpen)
        wbImportFile.Worksheets("Sheet1").Range("C3:M4").Copy
        ThisWorkbook.Worksheets("Sheet1").Range("B3").PasteSpecial (xlPasteAll)
    End If
    
End Sub

 

It seems like this parameter causes an error "filefilter:="Excel Files(*.xls*), *xls*". This problem happens only on Mac. There is no problems with Windows version of Excel.

 

Do you know when Microsoft will fix this?

Thanks.

 

 

2 Replies

I have the same problem, I had to run Excel in a Windows VM on my MAC to solve it..... there're other problems too with Excel for MacOS, data segmentation problems...

@VSachenok 

 

I've never worked with a mac, but, according to this, it appears that functionality requires some apple script. Sorry I can't be of more help than this.

 

https://docs.microsoft.com/en-us/previous-versions/office/developer/office-2010/hh710200(v=office.14...