Sign in to follow this  
Followers 0
trantrack

Unable to open Excel document in Autoit

13 posts in this topic

Good morning!

I'd like to start by saying that I have learned alot from this forum.  Thanks for all the posts on so many topics!  I am new to Autoit and like it very much.  This is my first post of hopefully many in the future. 

My issue today,

I am trying to open an excel document in Autoit but keep getting a UDF error, I think...

This is the code:

#include <Excel.au3>

Local $sFilePath = "book1.xlsx"
Local $oExcel = _ExcelBookOpen($sFilePath, 1, True)

This is the error I am receiving:

C:Program FilesAutoIt3IncludeExcel.au3 (191) : ==> The requested action with this object has failed.:
If $sPassword = "" And $sWritePassword = "" Then .WorkBooks.Open($sFilePath, Default, $fReadOnly)
If $sPassword = "" And $sWritePassword = "" Then .WorkBooks.Open($sFilePath, Default, $fReadOnly)^ ERROR

Excel will launch briefly and then close.  The file is present on the system

I must be overlooking something, but I am unable to figure out what I need to do to make it work.

Thanks for your help!!!

Share this post


Link to post
Share on other sites



The included Excel UDF that comes with AutoIt doesn't handle XLSX documents, you should look at water's rewrite of the UDF as it will work better with XLSX documents.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Hi and welcome to the forum!

 your script may have trouble finding the file.

this worked for me:

#include <Excel.au3>

Local $sFilePath = @ScriptDir & "\" & "book1.xlsx"
Local $oExcel = _ExcelBookOpen($sFilePath, 1, True)

Share this post


Link to post
Share on other sites

Thanks for your assistance, billo.  Luckly, the script is finding the file in this case.

I downloaded the new UDF's for excel and tried to run it with the #include <Excel Rewrite.au3> tag.

I updated Autoit to the Beta version (I believe it said it was a requirement).  Unfortunatly I am receiving this error now:

C:Program FilesAutoit_IncludesExcel Rewrite.au3(168,56) : ERROR: ObjGet() [built-in] called with wrong number of args.
        $oWorkbook = ObjGet("", $sCLSID_Workbook, $iCount + 1)
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:Program FilesAutoit_IncludesExcel Rewrite.au3(249,57) : ERROR: ObjGet() [built-in] called with wrong number of args.
            $oWorkbook = ObjGet("", $sCLSID_Workbook, $iIndex + 1)
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:Program FilesAutoit_IncludesExcel Rewrite.au3(1155,27) : ERROR: _ArrayTranspose(): undefined function.
        _ArrayTranspose($vResult)
        ~~~~~~~~~~~~~~~~~~~~~~~~^

It finishes by opening the UDF in SciTE.  Any idea what I have done wrong at this point?

Share this post


Link to post
Share on other sites

Are you running the script with the Beta or the release version? You can see in the output panel of Scite which version of AutoIt3 is being executed, if it's not 3.3.9.* you're not running the Beta.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Thanks for your assistance, billo.  Luckly, the script is finding the file in this case.

I downloaded the new UDF's for excel and tried to run it with the #include <Excel Rewrite.au3> tag.

I updated Autoit to the Beta version (I believe it said it was a requirement).  Unfortunatly I am receiving this error now:

C:Program FilesAutoit_IncludesExcel Rewrite.au3(168,56) : ERROR: ObjGet() [built-in] called with wrong number of args.

        $oWorkbook = ObjGet("", $sCLSID_Workbook, $iCount + 1)

        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:Program FilesAutoit_IncludesExcel Rewrite.au3(249,57) : ERROR: ObjGet() [built-in] called with wrong number of args.

            $oWorkbook = ObjGet("", $sCLSID_Workbook, $iIndex + 1)

            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:Program FilesAutoit_IncludesExcel Rewrite.au3(1155,27) : ERROR: _ArrayTranspose(): undefined function.

        _ArrayTranspose($vResult)

        ~~~~~~~~~~~~~~~~~~~~~~~~^

It finishes by opening the UDF in SciTE.  Any idea what I have done wrong at this point?

 

If you are using SciTE and pressing F5 to run it, you made the same mistake I did when i first tried out the Excel Rewrite UDF.

Pressing F5 runs the script with Production code. You need to press Alt-F5 to run the script with Beta code :graduated:

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Just FYI

I have been using the latest stable vers:  >Running:(3.3.8.1) and that is what I used to test it.

I had the same issue as trantrak did and fixed it as mentioned above.

 

Maybe this info helps...

Edited by billo

Share this post


Link to post
Share on other sites

You need to install the latest beta version of AutoIt and then run the script from SciTE by pressing Alt-F5 to run the script with the beta version.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

When u double click the exe file does it open ? Sometimes files are corrupt , pass protected and so on. If id doesnt open with double click  - it wont open with the UDF too.

Share this post


Link to post
Share on other sites

The UDF should be able to handle password protected workbooks. Just pass the passwords as parameters to the open function.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Ah!  That's what my mistake was.  I wasn't running the scripts in the beta version.

I tried as Shrapnel suggested and I am feeling great joy that it worked!!!

Thanks for all the help!!!

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Glad to be of service, trantrack :)

 

Water, maybe adding a helpful FYI about pressing alt-F5 to run the script in beta mode would be helpful to the people that do not know about it?  (not that it would help people that don't read it :mad2: )

 

Edit: and if you added it and people still complain, at least you could say RTFM!!

Edited by Shrapnel

Share this post


Link to post
Share on other sites

It's already mentioned on the first page of this thread where you download the UDF.

I've changed the font to red and bold for better readability.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

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
Sign in to follow this  
Followers 0