Jump to content

Why can't i save a new excel file?


ashly
 Share

Recommended Posts

I would like to create a new excel workbook and using below scripts.

But it fails with @error=5 and @extended=-2147352567

I can't find out which part is wrong. Please help me~~~

#include <Excel.au3>

Local $oResultExcel = _Excel_Open(False)
Local $oResultBook = _Excel_BookNew($oResultExcel, 1)
_Excel_BookSaveAs($oResultBook, "C:\test.xlsx", $xlWorkbookDefault)
If @error Then Exit MsgBox(0, "Error!", "Error saving workbook to '" & $oResultBook & "'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

Link to comment
Share on other sites

Which version of Office do you run?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

The decimal value of @extended translates to 0x80020009. This means: General Error.
Only the error text would give more detailed error information.

Which version of AutoIt do you run?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • 2 years later...

hi guys 

I am also facing the same error @error = , @extended = -2147352567 But here i am formatting the xls files to xlsx files .

Through Automation i downloaded the xls file and opened, while saving the file to xlsx it showing the above error

My AutoIt version - 3.3.14.2. All this time it is working fine , now it is throwing the error Says "Error While Saving Workbook to " 

I am attaching the AutoIt Script for your reference

Thanks

XlsToXlsx.au3

Link to comment
Share on other sites

Do you get a popup or error message when you save the workbook by hand ?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

If try to save the file after formatting , it stuck some times and some times and sometimes it is working if changed the file name

C:\Users\MasthanS\Perforce\InfactWorkspace\QAAutomation_FS\Infact\Automation_FactoryLogger\testData\08-10-2018\Run10\FactoryLogger_SmokeSuite\ShiftTest\ShiftSmokeTest\tc009\Intervaltc009_08_10_2018_22_17_18

 

This is my path where i am saving the files and also I am unable to close the excel files after formatting if some excel files are already open in taskbar.

if it is only one then it is closing otherwise it is not closing how can i close the opened excel workbook file only

thanks in advance

 

Link to comment
Share on other sites

Your path is 206 characters long. Including the filename this might exceed the Windows maximum length.
Can you please test with a shorter path (maybe the desktop)?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Yeah, it is working fine now , thank you water thank you so much for the help

than i need to change the path or reduce it

After formatting the file ,  above _Excel_Close() func unable to close the file if already excel workbook files are open in taskbar, please help me in how i can close the only specified  opened file 

Link to comment
Share on other sites

Great this problem could be solved :) 

For the other problem you need to use _Excel_BookClose. 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

It throwing the error 'Error saving workbook.'  

@error=1 and @extended =0 

At _Excel_BookClose Method it is showing the error

 

 

 

#include <Excel.au3>
#include <MsgBoxConstants.au3>

; Create application object
Local $oExcel = _Excel_Open()
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookOpen Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

; Create a new workbook, write some data and close it without saving
; Create the new workbook
Local $oWorkbook = _Excel_BookOpen($oExcel, "C:\Users\MasthanS.BSG\Downloads\Interval1" & ".xls")

If @error Then
    MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookSaveAs Example", "Error opening workbook '" & $CmdLine[1] & ".xls'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    _Excel_Close($oExcel)
    Exit
EndIf

; *****************************************************************************
; Save the workbook (xls) in another format (xlsx) to another directory and
; overwrite an existing version
; *****************************************************************************

Local $sWorkbook = "C:\Users\MasthanS.BSG\Downloads\Inter" & ".xlsx"
_Excel_BookSaveAs($oWorkbook, $sWorkbook, $xlOpenXMLWorkbook, True)


If @error Then Exit MsgBox ($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookSaveAs Example 1", "Error saving workbook to '" & $sWorkbook & "'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
;MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookSaveAs Example 1", "Workbook successfully saved as '" & $sWorkbook & "'.")
ShellExecute($sWorkbook)


; Close the workbook without saving
_Excel_BookClose($oWorkbook, False)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookClose Example 1", "Error saving workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookClose Example 1", "Workbook has been successfully closed.")

 

Link to comment
Share on other sites

#include <Excel.au3>
#include <MsgBoxConstants.au3>

; Create application object
Global $oExcel = _Excel_Open()
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookOpen Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

; Create a new workbook, write some data and close it without saving
; Create the new workbook
Local $oWorkbook = _Excel_BookOpen($oExcel, "C:\Users\MasthanS.BSG\Downloads\Interval1" & ".xls")

If @error Then
    MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookSaveAs Example", "Error opening workbook '" & $CmdLine[1] & ".xls'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    _Excel_Close($oExcel)
    Exit
EndIf

; *****************************************************************************
; Save the workbook (xls) in another format (xlsx) to another directory and
; overwrite an existing version
; *****************************************************************************

Global $sWorkbook = "C:\Users\MasthanS.BSG\Downloads\123" & ".xlsx"
_Excel_BookSaveAs($oWorkbook, $sWorkbook, $xlOpenXMLWorkbook, True)


If @error Then Exit MsgBox ($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookSaveAs Example 1", "Error saving workbook to '" & $sWorkbook & "'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
;MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookSaveAs Example 1", "Workbook successfully saved as '" & $sWorkbook & "'.")
ShellExecute($sWorkbook)


; Close the workbook without saving
_Excel_BookClose($oWorkbook, False)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookClose Example 1", "Error saving workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookClose Example 1", "Workbook has been successfully closed.")

 

Link to comment
Share on other sites

Did you have a look at the help file? All codes for @error are described there.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Is this the full script you run? Because I do not see a reason why $oWorkbook shouldn't be a valid object :(

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...