Jump to content

Need Help with Error


Recommended Posts

#Include <Excel.au3>
#Include <File.au3>
Dim $oExcel, $sExcelFile, $ms
Dim $fExcelVisible = 1 ;Change this to 0 for Production
While ProcessExists("EXCEL.EXE")
$ms = MsgBox(5,"","Process error.  You have an Excel sheet open.  You must close it in order to let this program work.  Please close it now.") ;Retry=4 and Cancel=2
    If $ms=2 Then Exit
Sleep(250)
WEnd
$sExcelFile = FileOpenDialog("Choose/Create Excel File", @ScriptDir, "(*.xls)") ;Changed $oExcel to $sExcelFile
If FileExists($sExcelFile) Then
MsgBox(0,"","open selected book__")
    $oExcel = _ExcelBookOpen($sExcelFile,$fExcelVisible, False);this will open the chosen xls file.
If IsObj($oExcel) Then ConsoleWrite("Excel book " & $sExcelFile & " has been opened." & @CRLF)
Else
$oExcel = _ExcelBookNew($fExcelVisible);this is here to create the xls file if it does not exist.
_ExcelBookSaveAs($oExcel,$sExcelFile) ;Save it immediately
    _ExcelWriteCell($oExcel,"Testing2",1,4);title line
EndIf
_ExcelBookClose($oExcel, 1) ;Save and close
ProcessClose("EXCEL.EXE")
MsgBox(0,"Done","Done",10)

Not sure why this is coming up as a error. Any help would be appriecated. 

$oExcel = _ExcelBookOpen($sExcelFile,$fExcelVisible, False)
$oExcel = ^ ERROR

 

 

 

You miss 100% of the shots you don't take. -Wayne Gretzky -Michael Scott

Link to comment
Share on other sites

Which version of AutoIt do you run?
What's the exact error text you see in the SciTE output pane?

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

I have the most current I believe, however I used the zip file. just got it a couple days ago.

>"C:\Users\vmitchell\Desktop\AutoIt\SciTe\..\autoit3.exe" /ErrorStdOut "J:\MCK Clinic Ops Training\Portal\Vaughn\Test\AutoIt Scripts\Test3.au3"    
"J:\MCK Clinic Ops Training\Portal\Vaughn\Test\AutoIt Scripts\Test3.au3" (13) : ==> Unknown function name.:
$oExcel = _ExcelBookOpen($sExcelFile,$fExcelVisible, False)
$oExcel = ^ ERROR
>Exit code: 1    Time: 4.956

Capture.PNG

Capture2.PNG

You miss 100% of the shots you don't take. -Wayne Gretzky -Michael Scott

Link to comment
Share on other sites

I see.
The Excel UDF has been completely rewritten with version 3.3.12.0 of AutoIt. The function names etc. have been changed.
Details can be found here: https://www.autoitscript.com/autoit3/docs/script_breaking_changes_excel_udf.htm

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

#Include <Excel.au3>
#Include <File.au3>


Dim $oExcel, $sExcelFile, $ms
Dim $fExcelVisible = 1 ;Change this to 0 for Production
While ProcessExists("EXCEL.EXE")
$ms = MsgBox(5,"","Process error.  You have an Excel sheet open.  You must close it in order to let this program work.  Please close it now.")
    If $ms=2 Then Exit
Sleep(250)
WEnd
$sExcelFile = FileOpenDialog("Choose/Create Excel File", @ScriptDir, "(*.xls)")
If FileExists($sExcelFile) Then
MsgBox(0,"","open selected book__")
   $oExcel = _Excel_Open($sExcelFile);this will open the chosen xls file.
If IsObj($oExcel) Then ConsoleWrite("Excel book " & $sExcelFile & " has been opened." & @CRLF)
Else
$oExcel = _Excel_Open()
$oWorkbook = _Excel_BookNew($oExcel, 2);this is here to create the xls file if it does not exist.

EndIf

Okay, I made the changes and the "Else" code is working great again, however the if will act like it is loading and then the excel will not load. I get no error so I am not sure what part of the code is not working. 

Might be easier to just go back to the old code >.<

You miss 100% of the shots you don't take. -Wayne Gretzky -Michael Scott

Link to comment
Share on other sites

#Include <Excel.au3>
#Include <File.au3>

Dim $oExcel, $sExcelFile, $ms
While ProcessExists("EXCEL.EXE")
$ms = MsgBox(5,"","Process error.  You have an Excel sheet open.  You must close it in order to let this program work.  Please close it now.")
    If $ms=2 Then Exit
Sleep(250)
WEnd
$sExcelFile = FileOpenDialog("Choose/Create Excel File", @ScriptDir, "(*.xls)")

If FileExists($sExcelFile) Then
MsgBox(0,"","Book Opened")
$oExcel = _Excel_Open ()
$oExcel = _Excel_BookOpen($oExcel,$sExcelFile) ;this will open the chosen xls file.
If IsObj($oExcel) Then ConsoleWrite("Excel book " & $sExcelFile & " has been opened." & @CRLF)

Else
$oExcel = _Excel_Open()
$oWorkbook = _Excel_BookNew($oExcel, 2);this is here to create the xls file if it does not exist.

EndIf

Okay, confirmed still a big noob. I got it working and I don't want to talk about it. Here it is just in case this helps anyone else. I don't know what I would do without you water.

You miss 100% of the shots you don't take. -Wayne Gretzky -Michael Scott

Link to comment
Share on other sites

I would add some minor modifications to make it more readable:

#Include <Excel.au3>
#Include <File.au3>

Global $oExcel, $sExcelFile, $ms
While ProcessExists("EXCEL.EXE")
    $iReply = MsgBox(5,"","Process error.  You have an Excel sheet open.  You must close it in order to let this program work.  Please close it now.")
    If $iReply = 2 Then Exit
    Sleep(250)
WEnd
$sExcelFile = FileOpenDialog("Choose/Create Excel File", @ScriptDir, "(*.xls)")
$oExcel = _Excel_Open()
If FileExists($sExcelFile) Then
    MsgBox(0,"","Book Opened")
    $oWorkbook = _Excel_BookOpen($oExcel,$sExcelFile) ;this will open the chosen xls file.
    If @error = 0 Then ConsoleWrite("Excel book " & $sExcelFile & " has been opened." & @CRLF)
Else
    $oWorkbook = _Excel_BookNew($oExcel, 2);this is here to create the xls file if it does not exist.
EndIf

 

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

Another idea is not to check for a running Excel instance but for open workbooks. 

If you like I can post an example. 

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

After _Excel_Open you could call _Excel_Booklist. If you get an empty array no workbooks are open. 

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