2

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
Comintern
  • 21,855
  • 5
  • 33
  • 80
witlex
  • 21
  • 2
  • You might want to take a look at [this question](http://stackoverflow.com/questions/35057385/refresh-querytable-throwing-general-odbc-error-vba-excel-2011-for-mac). – Comintern Sep 20 '16 at 14:40
  • Allready looked at it thank you. But it doesn't have a solution – witlex Sep 22 '16 at 14:07

0 Answers0