Jump to content
ashly

Why can't i save a new excel file?

Recommended Posts

ashly

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)

Share this post


Link to post
Share on other sites
ashly

@l3ill

Thanks for you reply.

The path is just for this post. I'm actually using another path to save it in my USB stick.

Share this post


Link to post
Share on other sites
water

Which version of Office do you run?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
water

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 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
ashly

I just changed the path to desktop then it works!

Don't know why i cannot save it to my USB.

Anyway, thank you so much, @l3ill  :D

Share this post


Link to post
Share on other sites
Shaik

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

Share this post


Link to post
Share on other sites
water

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


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Shaik

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

 

Share this post


Link to post
Share on other sites
water

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 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Shaik

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 

Share this post


Link to post
Share on other sites
water

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 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Shaik

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.")

 

Share this post


Link to post
Share on other sites
FrancescoDiMuro

@Shaik
Please use the Code tag.
Your code unintelligible.


Click here to see my signature:

Spoiler

Thoughts:

  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites
Shaik
#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.")

 

Share this post


Link to post
Share on other sites
water

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 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Shaik

it is showing like this 

1 - $oWorkbook is not an object or not a workbook object

Share this post


Link to post
Share on other sites
water

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 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
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

×