Jump to content

Recommended Posts

  • Moderators
Posted (edited)

@captainsensible how about living up to your name and actually posting your code, rather than expecting us to know what you're doing on lines 1-57...

Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Posted

Local $sWorkbook8 = "M:\cotr 2019\charts 2006\chart cotr f tff 2006.xlsm"
Local $oWorkbook8 = _Excel_BookOpen($oExcel, $sWorkbook8, False, True, Default, Default, 3)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookOpen Example 1", "Error opening '" & $sWorkbook8 & "'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
$oExcel.run("workbook_print")
_Excel_BookClose ( $oWorkbook8, False)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookClose Example 1", "Error saving workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookClose Example 1", "Workbook has been successfully closed.")
 

Posted (edited)

And the include for Excel.au3 for the UDF function you are using ...  check the excel functions in the help file.  But consider starting like this:

#include <Excel.au3>
#include <MsgBoxConstants.au3>

; Create application object
Local $oExcel = _Excel_Open()
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookOpen Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

 

Edited by Jfish

Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Posted

You are using the latest Excel UDF like the old version before it has been rewritten with AutoIt 3.3.11.4 back in 2014 (described here).
There have been script breaking changes (described here).

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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

 

Posted

#include <Excel.au3>
#include <MsgBoxConstants.au3>

; Create application object
Local $oExcel = _Excel_Open()
If @error Then Exit MsgBox(16, "Excel UDF: _Excel_BookOpen Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

; *****************************************************************************
; Open an existing workbook and return its object identifier.
; *****************************************************************************
; *****************************************************************************

Local $sWorkbook7 = "M:\cotr 2019\cotr price.xlsm"
Local $oWorkbook7 = _Excel_BookOpen($oExcel, $sWorkbook7, True, True, Default, Default, 0)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookOpen Example 1", "Error opening '" & $sWorkbook7 & "'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

Local $sWorkbook1 = "M:\cotr 2019\cotr f tff calc.xlsm"
Local $oWorkbook1 = _Excel_BookOpen($oExcel, $sWorkbook1, True, True, Default, Default, 0)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookOpen Example 1", "Error opening '" & $sWorkbook1 & "'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

Local $sWorkbook2 = "M:\cotr 2019\cotr fo tff calc.xlsm"
Local $oWorkbook2 = _Excel_BookOpen($oExcel, $sWorkbook2, True, True, Default, Default, 0)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookOpen Example 1", "Error opening '" & $sWorkbook2 & "'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

Local $sWorkbook3 = "M:\cotr 2019\cotr f disagg calc.xlsm"
Local $oWorkbook3 = _Excel_BookOpen($oExcel, $sWorkbook3, True, True, Default, Default, 0)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookOpen Example 1", "Error opening '" & $sWorkbook3 & "'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

Local $sWorkbook4 = "M:\cotr 2019\cotr fo disagg calc.xlsm"
Local $oWorkbook4 = _Excel_BookOpen($oExcel, $sWorkbook4, True, True, Default, Default, 0)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookOpen Example 1", "Error opening '" & $sWorkbook4 & "'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

Local $sWorkbook5 = "M:\cotr 2019\cotr f legacy calc.xlsm"
Local $oWorkbook5 = _Excel_BookOpen($oExcel, $sWorkbook5, True, True, Default, Default, 0)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookOpen Example 1", "Error opening '" & $sWorkbook5 & "'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

Local $sWorkbook6 = "M:\cotr 2019\cotr fo legacy calc.xlsm"
Local $oWorkbook6 = _Excel_BookOpen($oExcel, $sWorkbook6, True, True, Default, Default, 0)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookOpen Example 1", "Error opening '" & $sWorkbook6 & "'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)


Local $sWorkbook8 = "M:\cotr 2019\charts 2006\chart cotr f tff 2006.xlsm"
Local $oWorkbook8 = _Excel_BookOpen($oExcel, $sWorkbook8, False, True, Default, Default, 3)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookOpen Example 1", "Error opening '" & $sWorkbook8 & "'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
$oExcel.run("workbook_print")
_Excel_BookClose ( $oWorkbook8, False)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookClose Example 1", "Error saving workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookClose Example 1", "Workbook has been successfully closed.")
 

 

Posted

The script looks fine.
But as you work with a workbook with macros it is impossible to tell what happens when you open the workbook (autorun a macro).
Could you please strip down your workbook and post a reproducer (that still shows the problem) so we can have a look?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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

 

Posted

The workbook opens fine and even printing to the default printer works as expected.
I suggest to add a COM error handler (before the run method) for better diagnostic information:

; ...
Local $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")
$oExcel.Run("workbook_print")
Func _ErrFunc($oError)
    ; Do anything here.
    ConsoleWrite(@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _
            @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _
            @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _
            @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _
            @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _
            @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
            @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
            @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
            @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
            @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF)
EndFunc   ;==>_ErrFunc

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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

 

Posted

I have recently had two problems with Excel failing to work from AutoIt:

which was a result of a user using an add-in.

The second was on office 365 where I had to force a manual update and all was then well again.

Problem solving step 1: Write a simple, self-contained, running, replicator of your problem.

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
×
×
  • Create New...