Reputation: 6413
i'm using vba to open an .csv file
Sub open_csv_file()
Workbooks.Open("c:\test.csv")
ActiveWorkbook.Close
End Sub
It works, but with a side effect: when the csv file is opened, the original .xlsm file start to recalculate.
Is there a way to avoid the side effect?
ps. I've already set Excel calculation as Manual.
Upvotes: 1
Views: 1396
Reputation: 1719
The only workaround that seems to be working is to set Worksheet.EnableCalculation to False for each worksheet.
Try this
Sub open_csv_file()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
ws.EnableCalculation = False
Next ws
Workbooks.Open ("c:\users\test\desktop\test.csv")
ActiveWorkbook.Close
End Sub
Upvotes: 2
Reputation: 4848
The calling .xlsm file recalculates when opening a .csv file, but not when opening a .xls file. Renaming the .csv file to .xls before opening will prevent recalculation and still open the file as normal.
Sub open_csv_file()
Name "c:\test.csv" As "c:\test.xls"
Workbooks.Open "c:\test.xls", Format:=2
End Sub
Some error handling should be added to handle the situation where the new filename already exists.
Upvotes: 1
Reputation: 42528
One way to avoid the calculation is to open the file with another instance of Excel:
Dim app As Excel.Application
Dim csv As Workbook
Set app = New Excel.Application
app.Visible = True
Set csv = app.Workbooks.Open("c:\test.csv")
Upvotes: 4