Jadog Posted September 10, 2021 Share Posted September 10, 2021 (edited) I'm trying to open an excel file and save as CSV and I'm having trouble. Below is what I have: Local $oExcel, $oWorkbook $oExcel = _Excel_Open() If @error Then Exit MsgBox($MB_SYSTEMMODAL, "_Excel_Open Error", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended) $oWorkbook = _Excel_BookOpen($oExcel, "C:\Users\think\Desktop\Update.xls") Switch @error Case 1 Exit MsgBox($MB_SYSTEMMODAL, "_Excel_BookOpen Error 1", "$oExcel is not an object or not an application object") Case 2 Exit MsgBox($MB_SYSTEMMODAL, "_Excel_BookOpen Error 2", "Specified $sFilePath does not exist") Case 3 Exit MsgBox($MB_SYSTEMMODAL, "_Excel_BookOpen Error 3", "Unable to open $sFilePath. @extended is set to the COM error code returned by the Open method") EndSwitch ;Save as CSV $oWorkbook = _Excel_BookSaveAs("C:\Users\think\Desktop\Update.csv", "csv", 0, 1) Excel opens the workbook but does not save it as a CSV. What am I doing wrong? Edited September 10, 2021 by Jadog Link to comment Share on other sites More sharing options...
Subz Posted September 10, 2021 Share Posted September 10, 2021 (edited) _Excel_BookSaveAs($oWorkbook, @DesktopDir & "\Update.csv", $xlCSV) See the help file for more info: https://www.autoitscript.com/autoit3/docs/libfunctions/_Excel_BookSaveAs.htm Edited September 10, 2021 by Subz Link to comment Share on other sites More sharing options...
Musashi Posted September 11, 2021 Share Posted September 11, 2021 On 9/10/2021 at 12:58 PM, Jadog said: ;Save as CSV $oWorkbook = _Excel_BookSaveAs("C:\Users\think\Desktop\Update.csv", "csv", 0, 1) What am I doing wrong? The first parameter is the Workbook object not the Path and filename of the file to be saved to . As I already wrote to you in thread unable-to-open-excel-file , you should pay more attention to Function parameters and Return Values . #include <Excel.au3> #include <MsgBoxConstants.au3> Local $oExcel, $oWorkbook $oExcel = _Excel_Open() If @error Then Exit MsgBox($MB_SYSTEMMODAL, "_Excel_Open Error", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended) $oWorkbook = _Excel_BookOpen($oExcel, "C:\Users\think\Desktop\Update.xls") Switch @error Case 1 Exit MsgBox($MB_SYSTEMMODAL, "_Excel_BookOpen Error 1", "$oExcel is not an object or not an application object") Case 2 Exit MsgBox($MB_SYSTEMMODAL, "_Excel_BookOpen Error 2", "Specified $sFilePath does not exist") Case 3 Exit MsgBox($MB_SYSTEMMODAL, "_Excel_BookOpen Error 3", "Unable to open $sFilePath. @extended is set to the COM error code returned by the Open method") EndSwitch ;Save as CSV Local $sWorkbook = "C:\Users\think\Desktop\Update.csv" ; Info : XlFileFormat enumeration -> $xlCSV or $xlCSVWindows ? _Excel_BookSaveAs($oWorkbook, $sWorkbook, $xlCSV, True) ; True = overwrites an existing file If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookSaveAs", "Error saving workbook to '" & $sWorkbook & "'." & @CRLF & "@error = " & @error & ", @extended = " & @extended) "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now