Is there a way to import data from .csv to active excel sheet?

前端 未结 4 2102
无人及你
无人及你 2020-12-05 19:40

I have a csv file always named the same, called SO2PO.csv. It has data that I import into an excell sheet called PO Data, in a workbook called Open Order. I need to find a w

4条回答
  •  -上瘾入骨i
    2020-12-05 20:14

    If you're going to use querytables make sure you clean up after, leftover query tables caused me a few headaches in a downstream process.

    ' get the file to the data sheet
    Set ws = ActiveWorkbook.Sheets("Data")
    With ws.QueryTables.Add(Connection:="TEXT;" & "mydata.csv", Destination:=ws.Range("A1"))
        .TextFileParseType = xlDelimited
        .TextFileCommaDelimiter = True
        .Refresh
    End With
    
    ' delete the querytable if there is one
    On Error GoTo nothingtodelete
        Sheets("Data").QueryTables(1).SaveData = False
        Sheets("Data").QueryTables.Item(1).Delete 
    nothingtodelete:
    

提交回复
热议问题