aiter

word udf - hangs on _Word_DocOpen

22 posts in this topic

#1 ·  Posted (edited)

I have created an executable that opens a word document using _Word_DocOpen.

I call this executable fom within another application using dos /c myexe

When my word document extension is '.doc', the executable hangs on _Word_DocOpen

The syntax I use is _WordDocOpen($oWord,$PathToFile, default, default,true)

It does not return any error messages, just hangs. This causes a big problem.

When the document extension is '.docx' there are no problems.

When I run the executable from cmd, there are no problems regardless of the file extension being .doc or .docx

Can anyone tell me what is happening here?

 

Edited by aiter
spelling

Share this post


Link to post
Share on other sites



Welcome to AutoIt and the forum!

We need a bit of additional information to help you:

  • Which version of Autoit do you run?
  • Which version of Office do you use?
  • Is there any automatic processing started when you open the document (macros, retrieving some external data ...)?

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.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
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

AutoIt version : 3.3.1.4.2

Office : 10

The document has no macro code embedded.

 

 

Share this post


Link to post
Share on other sites

Is it possible to post the Word document here? Or send it as a forum message?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.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
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

This script opens your document without any problems:

#include <Word.au3>
Global $oWord = _Word_Create()
ConsoleWrite(@error & @CRLF)
Global $oDoc = _Word_DocOpen($oWord, @ScriptDir & "\doctest.doc")
ConsoleWrite(@error & @CRLF)

Windows 7 64 bit, office 2010 32 bit, AutoIt 3.3.12.0, running as 32 bit.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.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
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

For me, too. F5 or compile then run the exe via cmd presents no issues.

Where it is failing, is when I run the exe from within another environment (a database system). The exe is invoked from a program which does a call out to dos to do it eg EXECUTE dos /c MyExe.exe SomeParams.

Excel works by the way, which suggests it is the more robust,.

Is it perhaps the enviromentals (eg paths etc) have been changed when the program shelled out to dos to call the exe?

Anyway, thanks for your assistance.

 

Edited by aiter
grammar

Share this post


Link to post
Share on other sites

I created a second AutoIt script and it works with run and shellexecute.

; Run(@ComSpec & " /c " & 'test.exe', "", @SW_HIDE)
; Runwait('test.exe', "", @SW_HIDE)
ShellExecute('test.exe', "")

So yes, i think it is the way the Autoit script gets called from the main application.

  • Which language do you use for the calling program?
  • Can you post the line where you call the Autoit script?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.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
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

The language is a version of basic (pick/unidata)

EXECUTE "dos /c c:\autoit\myproj\myexe.exe ":Param

Share this post


Link to post
Share on other sites

Could you please add

Opt("TrayIconDebug", 1)

at the top of your AutoIt script?
When the script hangs move the mouse over the AutoIt Tray Icon and you will see the currently executing statement.
Maybe this gives us an idea what goes on :)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.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
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

WIll try that, thanks.

Share this post


Link to post
Share on other sites

I managed to get an error message

error code of 3

extended -2147352567

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Unfortunately -2147352567 (decimal) or 0x80020009 (hex) stands for: General error.

COM errors are hard to debug in AutoIt 3.3.14.2. But the following script should present detailed error information in a separate window:

#include <Word.au3>
#include <Debug.au3>
_DebugSetup()
_DebugCOMError()

Global $oWord = _Word_Create()
Global $oDoc = _Word_DocOpenEX($oWord, @ScriptDir & "\doctest.doc", Default, Default, True)
ConsoleWrite(@error & @CRLF)

Func _Word_DocOpenEX($oAppl, $sFilePath, $bConfirmConversions = Default, $iFormat = Default, $bReadOnly = Default, $bRevert = Default, $bAddToRecentFiles = Default, $sOpenPassword = Default, $sWritePassword = Default)
    If $bConfirmConversions = Default Then $bConfirmConversions = False
    If $iFormat = Default Then $iFormat = $WdOpenFormatAuto
    If $bReadOnly = Default Then $bReadOnly = False
    If $bRevert = Default Then $bRevert = False
    If $bAddToRecentFiles = Default Then $bAddToRecentFiles = False
    If $sOpenPassword = Default Then $sOpenPassword = ""
    If $sWritePassword = Default Then $sWritePassword = ""
    If Not IsObj($oAppl) Then Return SetError(1, 0, 0)
    If Not FileExists($sFilePath) Then Return SetError(2, 0, 0)
    If StringInStr($sFilePath, "\") = 0 Then $sFilePath = @ScriptDir & "\" & $sFilePath
    Local $oDoc = $oAppl.Documents.Open($sFilePath, $bConfirmConversions, $bReadOnly, $bAddToRecentFiles, _
            $sOpenPassword, "", $bRevert, $sWritePassword, "", $iFormat)
    If @error Or Not IsObj($oDoc) Then Return SetError(3, @error, 0)
    ; If a read-write document was opened read-only then return an error
    If $bReadOnly = False And $oDoc.Readonly = True Then Return SetError(0, 1, $oDoc)
    Return $oDoc
EndFunc   ;==>_Word_DocOpen

 

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.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
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

This script runs perfectly from F5 and from a cmd prompt.

Unfortunately when I run it from my database environment, the program hangs and is totally unresponsive. I managed to see an output of 0 (zero) and thats it. 

Share this post


Link to post
Share on other sites

Can you recreate the error situation from post #12?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.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
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

I can see the error when I use the normal open (_Word_DocOpen), i.e it gets past the open command and then reports the error and exits

When I use the _Word_DocOpenEx the program hangs again, no output.

 

 

Share this post


Link to post
Share on other sites

Then let's try this one. It doesn't rely on the Debug UDF:

#include <Word.au3>

Global $__iOL_Debug = 0 ; Debug level. 0 = no debug information, 1 = Debug info to console, 2 = Debug info to MsgBox, 3 = Debug Info to File
Global $__sOL_DebugFile = @ScriptDir & "\Outlook_Debug.txt" ; Debug file if $__iOL_Debug is set to 3
Global $__oOL_Error ; COM Error handler

_OL_ErrorNotify(2)
Global $oWord = _Word_Create()
Global $oDoc = _Word_DocOpenEX($oWord, @ScriptDir & "\doctest.doc", Default, Default, True)
Exit

Func _Word_DocOpenEX($oAppl, $sFilePath, $bConfirmConversions = Default, $iFormat = Default, $bReadOnly = Default, $bRevert = Default, $bAddToRecentFiles = Default, $sOpenPassword = Default, $sWritePassword = Default)
    If $bConfirmConversions = Default Then $bConfirmConversions = False
    If $iFormat = Default Then $iFormat = $WdOpenFormatAuto
    If $bReadOnly = Default Then $bReadOnly = False
    If $bRevert = Default Then $bRevert = False
    If $bAddToRecentFiles = Default Then $bAddToRecentFiles = False
    If $sOpenPassword = Default Then $sOpenPassword = ""
    If $sWritePassword = Default Then $sWritePassword = ""
    If Not IsObj($oAppl) Then Return SetError(1, 0, 0)
    If Not FileExists($sFilePath) Then Return SetError(2, 0, 0)
    If StringInStr($sFilePath, "\") = 0 Then $sFilePath = @ScriptDir & "\" & $sFilePath
    Local $oDoc = $oAppl.Documents.Open($sFilePath, $bConfirmConversions, $bReadOnly, $bAddToRecentFiles, _
            $sOpenPassword, "", $bRevert, $sWritePassword, "", $iFormat)
    If @error Or Not IsObj($oDoc) Then Return SetError(3, @error, 0)
    ; If a read-write document was opened read-only then return an error
    If $bReadOnly = False And $oDoc.Readonly = True Then Return SetError(0, 1, $oDoc)
    Return $oDoc
EndFunc   ;==>_Word_DocOpen

Func _OL_ErrorNotify($iDebug, $sDebugFile = "")

    If Not IsInt($iDebug) Or $iDebug < -1 Or $iDebug > 4 Then Return SetError(1, 0, 0)
    If $sDebugFile = "" Then $sDebugFile = @ScriptDir & "\Outlook_Debug.txt"
    Switch $iDebug
        Case -1
            Local $avDebug[4] = [3]
            $avDebug[1] = $__iOL_Debug
            $avDebug[2] = $__sOL_DebugFile
            $avDebug[3] = IsObj($__oOL_Error)
            Return $avDebug
        Case 0
            $__iOL_Debug = 0
            $__sOL_DebugFile = ""
            $__oOL_Error = 0
        Case Else
            $__iOL_Debug = $iDebug
            $__sOL_DebugFile = $sDebugFile
            ; A COM error handler will be initialized only if one does not exist
            If ObjEvent("AutoIt.Error") = "" Then
                $__oOL_Error = ObjEvent("AutoIt.Error", "__Outlook_ErrorHandler") ; Creates a custom error handler
                If @error <> 0 Then Return SetError(2, @error, 0)
                Return SetError(0, 1, 1)
            ElseIf ObjEvent("AutoIt.Error") = "__Outlook_ErrorHandler" Then
                Return SetError(0, 0, 1) ; COM error handler already set by a call to this function
            Else
                Return SetError(3, 0, 0) ; COM error handler already set to another function
            EndIf
    EndSwitch
    Return 1

EndFunc   ;==>_OL_ErrorNotify

Func __Outlook_ErrorHandler()

    Local $bHexNumber = Hex($__oOL_Error.number, 8)
    Local $aVersionInfo[5] ; _OL_VersionInfo()
    Local $sError = "COM Error Encountered in " & @ScriptName & @CRLF & _
            "OutlookEX UDF version = " & $aVersionInfo[2] & "." & $aVersionInfo[3] & "." & $aVersionInfo[4] & @CRLF & _
            "@AutoItVersion = " & @AutoItVersion & @CRLF & _
            "@AutoItX64 = " & @AutoItX64 & @CRLF & _
            "@Compiled = " & @Compiled & @CRLF & _
            "@OSArch = " & @OSArch & @CRLF & _
            "@OSVersion = " & @OSVersion & @CRLF & _
            "Scriptline = " & $__oOL_Error.scriptline & @CRLF & _
            "NumberHex = " & $bHexNumber & @CRLF & _
            "Number = " & $__oOL_Error.number & @CRLF & _
            "WinDescription = " & StringStripWS($__oOL_Error.WinDescription, 2) & @CRLF & _
            "Description = " & StringStripWS($__oOL_Error.Description, 2) & @CRLF & _
            "Source = " & $__oOL_Error.Source & @CRLF & _
            "HelpFile = " & $__oOL_Error.HelpFile & @CRLF & _
            "HelpContext = " & $__oOL_Error.HelpContext & @CRLF & _
            "LastDllError = " & $__oOL_Error.LastDllError
    If $__iOL_Debug > 0 Then
        If $__iOL_Debug = 1 Then ConsoleWrite($sError & @CRLF & "========================================================" & @CRLF)
        If $__iOL_Debug = 2 Then MsgBox(64, "Outlook UDF - Debug Info", $sError)
        If $__iOL_Debug = 3 Then FileWrite($__sOL_DebugFile, @YEAR & "." & @MON & "." & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC & " " & @CRLF & _
                "-------------------" & @CRLF & $sError & @CRLF & "========================================================" & @CRLF)
    EndIf

EndFunc   ;==>__Outlook_ErrorHandler

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.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
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Will be back later.

 

Share this post


Link to post
Share on other sites

Hi again.  I compiled the script above as CUI.  Understand the environment I am running this program from will not tolerate window gui sort of popups, will not happen.

So I tried to change it to write the debug info to file, did not work.

I used procexplorer.exe to find the cmd running the program and looked at properties. The attached screenshot provides that information.

What about if I tried opening 'word.application' as an object and tried to open the file that way?

At the end of the day, the error is in opening a doc file as opposed to a .docx file - surely that must provide a clue?

 

Capture.PNG

Share this post


Link to post
Share on other sites
On 22.7.2016 at 5:15 PM, water said:

_OL_ErrorNotify(2)

Change this to "_OL_ErrorNotify(3)" and the COM error messages get written to

@ScriptDir & "\Outlook_Debug.txt"

When you say

Quote

So I tried to change it to write the debug info to file, did not work.

what does it mean? You get an error message, not file is being created, the created file is empty ...?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.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
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

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