I'm saving the data in a worksheet of an XLSM workbook to a CSV file. That part works file. But when I save to CSV, it closes the XLSM file. I'd like to leave the XLSM file open. Is there a way to do that and close the CSV file all under one macro?
This is what I have thus far:
'Since this macro ended without error, save the workbook as a CSV file
ActiveWorkbook.SaveAs Filename:=strPathName & strCSVName, _
FileFormat:=xlCSVMSDOS, CreateBackup:=False
'Set an object for the CSV file
Set objCsvFile = ActiveWorkbook
'The Save to CSV closed the workbook. Open the XLSM workbook
Workbooks.Open strPathName & "\" & strXlsmName
If I try to close the CSV file now, the macro abruptly halts.
Thanks for looking at this.
.Copy
instead of.Move
). But if that's not an option you can go with @Ampersand proposal. Anyway, you need to have (in the end) at least one.xlsm
file open and running (to host the VBA code). – Ralph