Jump to content
SkysLastChance

Need Help with Error

Recommended Posts

SkysLastChance
#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

 

 

 


Life's simple. You make choices and you don't look back.

Share this post


Link to post
Share on other sites
water

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 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-09-01 - Version 1.3.4.0) - 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
SkysLastChance

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


Life's simple. You make choices and you don't look back.

Share this post


Link to post
Share on other sites
water

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

  • Like 1

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-09-01 - Version 1.3.4.0) - 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
SkysLastChance

Oh wow, Thank you. :)


Life's simple. You make choices and you don't look back.

Share this post


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


Life's simple. You make choices and you don't look back.

Share this post


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


Life's simple. You make choices and you don't look back.

Share this post


Link to post
Share on other sites
water

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

 

  • Like 2

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-09-01 - Version 1.3.4.0) - 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
SkysLastChance

So Clean. I really appreciate you taking the time to clean that up for me. Thank you so much.:)


Life's simple. You make choices and you don't look back.

Share this post


Link to post
Share on other sites
water

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

If you like I can post an example. 

  • Like 1

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-09-01 - Version 1.3.4.0) - 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
SkysLastChance

Yeah that would be great. I am always trying to improve my code.


Life's simple. You make choices and you don't look back.

Share this post


Link to post
Share on other sites
water

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

  • Like 1

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-09-01 - Version 1.3.4.0) - 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

×