After the Excel sheets in the workbook are saved as .csv, you cannot return to .xlsm

I have a book with several sheets. I press the button (tape), and the subroutine saves several sheets in the form of .csv, issues a shell for some Java code, and then returns. The problem is that as soon as it returns, the workbook has been converted to a CSV file (the last saved), and further .xlsm operations are not possible.

How to fix it?

Amendment:

Has nothing to do with Java or the shell. WHEN I do it:

Sheets("someSheet").SaveAs Filename:=someName, FileFormat:=xlCSV 

this changes the entire workbook to someSheet.csv. Then the behavior of the book becomes strange. I could not save as .csv without changing EVERYONE.

+4
source share
2 answers

Use SaveCopyAs .

It leaves your original book as it is and saves a copy. It requires 2007 or newer, but since you mention the ribbon button, which should be fine. Link:

 ActiveWorkbook.SaveCopyAs "C:\TEMP\XXXX.XLS" 

http://msdn.microsoft.com/en-us/library/office/bb178003(v=office.12).aspx

+3
source

In Excel, the Save As operation creates a new copy of the workbook with a new name and format / style, then closes the old one.

The .csv file does not support macros, so your book behaves the way it was designed.

To return to the original workbook after Save As , you will need to open the original workbook again and close the new .csv workbook.

Otherwise, you can create your own Export method to simply export the data on each sheet to a CSV file, but this seems unnecessarily complicated.

+2
source

All Articles