Jump to content

Recommended Posts

For some reason I'm having trouble with the below script. A year ago it was running fine.

 

$oExcel = _Excel_BookOpen("C:\Users\think\Desktop\ExcelFileHere.xls", 1)
            If @error = 1 Then
                MsgBox(0, "Error!", "Unable to Create the Excel Object")
                Exit
            ElseIf @error = 2 Then
                MsgBox(0, "Error!", "File does not exist!")
                Exit
            EndIf

 

Link to post
Share on other sites
2 hours ago, Jadog said:

For some reason I'm having trouble with the below script. A year ago it was running fine.

 

$oExcel = _Excel_BookOpen("C:\Users\think\Desktop\ExcelFileHere.xls", 1)
            If @error = 1 Then
                MsgBox(0, "Error!", "Unable to Create the Excel Object")
                Exit
            ElseIf @error = 2 Then
                MsgBox(0, "Error!", "File does not exist!")
                Exit
            EndIf

I don't use Excel, but according to the help, shouldn't it look like this ? :

#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, @ScriptDir & "\Extras\_Excel1.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

; [...]

 

Musashi-C64.png

"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 post
Share on other sites

Which version of AutoIt do you run?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2021-11-10 - Version 1.6.0.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (NEW 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 (NEW 2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

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

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to post
Share on other sites
3 hours ago, Jadog said:

My help doesn't show that one. Is there an online help somewhere that shows this?

My script is a little variation of the example from the help on _Excel_BookOpen .

Quote

Parameters

$oExcel   Excel application object where you want to open the workbook
$sFilePath   Path and filename of the file to be opened

According to this, the first parameter must be an Excel application object, not a path. Your code snippet is also missing the preceding call of _Excel_Open . It was apparently different in older versions, hence the question from @water.

Take a look at : https://www.autoitscript.com/wiki/Excel_UDF

Quote

It's mandatory now to call function _Excel_Open before any other function (except _Excel_BookAttach). This function didn't exist in the old UDF. @extended is set if Excel was already running.

Musashi-C64.png

"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 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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...