Trying to adding table from csv to new sheet in existing Excel file - ending up empty table

dikken20

Board Regular
Joined
Feb 25, 2009
Messages
130
Office Version
  1. 2010
Platform
  1. Windows
Hello

Been using an excel sheet for years now.
One of its functionalities is to load a table from an other CSV file and paste its data in a "temp" sheet in order to process the data.
The processed data then copying to its proper sheet while the "temp" sheet is deleted.

One day the process didn't work.
At first I thought that the CSV structured file changed so it can't use the data as it should.
Looking at the CSV today - it looks fine actually.
So I just checked it using F8 line after line, and I realized that the data from the CSV file does not load on the "temp" sheet anymore!
Nothing changed in the code plus the CSV file remain the same structured.

This is the code:

VBA Code:
Sheets.Add After:=Sheets(Sheets.Count)
    Sheets(Sheets.Count).Name = "temp"
    Sheets("temp").Activate
    With ActiveSheet.QueryTables.Add(Connection:="TEXT;C:\user\Yesterday.csv", _
        Destination:=Range("$A$1"))
        .Name = "Yesterday"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .TextFilePromptOnRefresh = False
        .TextFilePlatform = 1255
        .TextFileStartRow = 1
        .TextFileParseType = xlDelimited
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileConsecutiveDelimiter = False
        .TextFileTabDelimiter = False
        .TextFileSemicolonDelimiter = False
        .TextFileCommaDelimiter = True
        .TextFileSpaceDelimiter = False
        .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
        .TextFileTrailingMinusNumbers = True
'        .refresh BackgroundQuery:=False
    End With

Help?
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
If you perform the macro actions manually, can you still add a sheet "temp"?
 
Upvote 0
The "temp" sheet added to the file using the macro, and can be added manually (to be precise - it is added in another name and changed to "temp" )

Basically everything works ok, its just the data that is not "copied" / retrieved to the "temp" sheet and therefore there is not data to be processed while the CSV source data contain data (meaning, it's not empty)
 
Upvote 0
Try un-commenting the refresh line. That is, change:

VBA Code:
'        .refresh BackgroundQuery:=False
    End With

to this

VBA Code:
        .refresh BackgroundQuery:=False
    End With
 
Upvote 0

Forum statistics

Threads
1,214,585
Messages
6,120,391
Members
448,957
Latest member
Hat4Life

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top