open a csv file in an active worksheet vba on mac

547 views Asked by At

I am trying to rewrite my windows VBA code so i can use it on a Mac computer. But somehow it is not possible to load the information into an active worksheet on mac.

Where MyFiles is the csv file opened by the code of http://www.rondebruin.nl/mac/mac015.html . I broke down the code a bit because i thought it didn't recognize the workbook. But i think the problem lies in the work book.

Set ws = ActiveWorkbook.Sheets("1. Pledges (ruw)")

    MyFiles = MacScript(MyScript)
    On Error GoTo 0


    If MyFiles <> "" Then
        With Application
            .ScreenUpdating = False
            .EnableEvents = False
        End With

        With ws.QueryTables.Add(Connection:="TEXT;" & MyScript, Destination:=ws.Range("A1"))
            .TextFileParseType = xlDelimited
            .TextFileCommaDelimiter = True
            .Refresh
        End With

        If ws.Range("A2").Value = vbNullString Then
            ws.rows("2").EntireRow.Delete
        End If

        With Application
            .ScreenUpdating = True
            .EnableEvents = True
        End With
    End If

End Sub

Some how it always crashes on the .refresh even if i use the code of robin the bruijn i can't use the querytables which work perfectly on windows.

Original windows code:

Dim ws As Worksheet, strFile As String

    Set ws = ActiveWorkbook.Sheets("1. Pledges (ruw)") 'set to current worksheet name

    strFile = Application.GetOpenFilename("Text Files (*.csv),*.csv", , "Please selec text file...")

    With ws.QueryTables.Add(Connection:="TEXT;" & strFile, Destination:=ws.Range("A1"))
         .TextFileParseType = xlDelimited
         .TextFileCommaDelimiter = True
         .RefreshOnFileOpen = False
         .BackgroundQuery = True
         .SaveData = True

    End With

    If ws.Range("A2").Value = vbNullString Then
        ws.rows("2").EntireRow.Delete
    End If
0

There are 0 answers