Open a txt-file within a macro (mac, excel 2016) RRS feed

  • Question

  • With Excel 2016 on the Mac it is not possible to open a txt file within a macro. Outside the macro there are no problems. With Excel 2011 I also had no problems.
    • Edited by knabenchor Tuesday, February 21, 2017 6:59 PM
    Tuesday, February 21, 2017 6:24 PM

All replies

  • Hi knabenchor,

    you had mentioned that with Excel 2016 on Mac you are not able to open text file with macro and Outside the macro there are no problems.

    do you mean you can open it using user interface.

    I can see that you can also open it using Excel 2011.

    I don't know how you tried.

    if possible please try to post your macro.

    you can also refer links below in which you can find some example codes that may help you to solve your issue.

    Use an Open File dialog in VBA with both Mac and Windows

    Select files on a Mac (GetOpenFilename)

    Function myGetOpenFileName(Optional sPath As String) As String
    Dim sFile As String
    Dim sMacScript As String
        If isMac Then
            If sPath = vbNullString Then
                sPath = "the path to documents folder"
                sPath = " alias """ & sPath & """"
            End If
            sMacScript = "set sFile to (choose file of type ({" & _
                """"", ""org.openxmlformats.spreadsheetml.sheet""," & _
                """public.comma-separated-values-text"", ""public.text"", ""public.csv""," & _                   """org.openxmlformats.spreadsheetml.sheet.macroenabled""}) with prompt " & _
                """Select a file to import"" default location " & sPath & ") as string" _
                & vbLf & _
                "return sFile"
             Debug.Print sMacScript
            sFile = MacScript(sMacScript)
        Else 'windows
            sFile = Application.GetOpenFilename("CSV files,*.csv,Excel 2007 files,*.xlsx", 1, _
                "Select file to import from", "&Import", False)
        End If
        myGetOpenFileName = sFileEnd Function



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Wednesday, February 22, 2017 1:02 AM