I am using excel-vba to access a closed .csv file
created by another program.
- The code below just goes through each cell and copies the value from the closed excel file to same cell in the open workbook.
- The first
.formula
line works with a .xls file, the commented out.formula
line referencing a .csv file does not - I get"#REF!"
in every cell.
I assume that the error that I get is due to the fact that I haven't stated it is not a "standard" .xls
file?
- The final code will read from a
.csv
file that is appended to every so often and therefore it has to remain closed. - The software that creates the
.csv
file is not able to output to.xls
file. It will be coded so that my macro will resume from where it left off rather than doing the whole worksheet every time.
Any help would be much appreciated.
Sub GetData()
Dim RowNumber As Integer
Dim ColNumber As Integer
For RowNumber = 1 To 100
For ColNumber = 1 To 104
With Cells(RowNumber, ColNumber)
.Formula = "='C:\Documents and Settings\admin\Desktop\[data.xls]Sheet1'!" & Cells(RowNumber, ColNumber).Address
'.Formula = "='C:\Documents and Settings\admin\Desktop\[data1.csv]Sheet1'!" & Cells(RowNumber, ColNumber).Address
.Value = .Value
End With
Next
Next
End Sub