SkysLastChance

Need Help with Error

12 posts in this topic

#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

 

 

 


Sky

Share this post


Link to post
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 (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2016-12-04 - Version 1.2.2.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
Tutorials:
ADO - Wiki

 

Share this post


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


Sky

Share this post


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

1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2016-12-04 - Version 1.2.2.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
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Oh wow, Thank you. :)


Sky

Share this post


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


Sky

Share this post


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


Sky

Share this post


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

 

2 people like this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2016-12-04 - Version 1.2.2.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
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

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


Sky

Share this post


Link to post
Share on other sites

#10 ·  Posted

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

If you like I can post an example. 

1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2016-12-04 - Version 1.2.2.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
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#11 ·  Posted

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


Sky

Share this post


Link to post
Share on other sites

#12 ·  Posted

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

1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2016-12-04 - Version 1.2.2.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
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