Weisgarnix

Error with _Word_DocFindReplace

48 posts in this topic

Hi.

I get an error replacing text in a document. @error = 3, @extended = 0. Where can I get further information about what that means?
AutoIt Help just says: "3 - An error occurred when the replace operation was executed. @extended is set to the COM error code".
But where can I find further information about this COM error code?

Thank you and best regards,
Weisgarnix

Share this post


Link to post
Share on other sites



Can you please post the line where you call _Wird_DocFindReplace?

1 person likes this

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

#3 ·  Posted (edited)

Sry for the big delay!

Here is the line of code:

_pmailwordreplacetext(@TempDir&"\PMail\Einladung_Test.docx", $aGrid)

Func _pmailwordreplacetext($wordfilepath, $snrarray)
    ; Create application object
    Local $oWord = _Word_Create(False)
    If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFindReplace Example", _
        "Error creating a new Word application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    ; Open document
    Local $oDoc = _Word_DocOpen($oWord, $wordfilepath)
    If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFindReplace Example", _
            "Error opening '"&$wordfilepath&"'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    ; *****************************************************************************
    ; Replace operation
    ; *****************************************************************************
    ;DEBUG!!!
    _ArrayDisplay($snrarray)
    $snrarraysize=UBound($snrarray)
    $i=0
    While($i < $snrarraysize)
        _Word_DocFindReplace($oDoc, $snrarray[$i][0], $snrarray[$i][1])
        If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFindReplace Example", _
                "Error replacing text in the document." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
        $i+=1
    WEnd
    ;MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFindReplace Example", "Paragraph control character successfully replaced.")
    _Word_DocClose($oDoc)
    _Word_Quit($oWord)
EndFunc

Does this help? Otherwise I can also send you the complete sourcecode including corresponding files. The array seems to be ok, I already checked that.

This is the error message:

Quote

---------------------------
Word UDF: _Word_DocFindReplace Example
---------------------------
Error replacing text in the document.

@error = 3, @extended = 0
---------------------------
OK   
---------------------------


Unfortunately, I have no idea how to find out what that means :(

Thank you a lot and best regards,
Weisgarnix

Edited by Weisgarnix

Share this post


Link to post
Share on other sites

#4 ·  Posted

The @error codes are described in the AutoIt help file. 

1 person likes this

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

#5 ·  Posted (edited)

3 - Error occurred when opening specified document. @extended is set to the COM error code

The COM error codes are not in the Autoit Helpfile :(

Edited by Weisgarnix

Share this post


Link to post
Share on other sites

#6 ·  Posted

It just means that either the "Word to be replaced" is the same as the "Word replacement" or that it couldn't find the word to replace.  For example if you look at the example below, it would fail on "Thursday" and also the last array item as Monday has already been replaced by Sunday.

Hope that makes sense :)

#include <Word.au3>

Local $aWeekDays[7][2] = [["Monday", "Sunday"],["Tuesday", "Saturday"],["Wednesday","Friday"],["Thusday","Thusday"],["Friday","Wednesday"],["Saturday","Tuesday"],["Monday","Sunday"]]
_pmailwordreplacetext(@ScriptDir & "\WordReplace.docx", $aWeekDays)

Func _pmailwordreplacetext($wordfilepath, $snrarray)
    ; Create application object
    Local $oWord = _Word_Create(False)
    If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFindReplace Example", _
        "Error creating a new Word application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    ; Open document
    Local $oDoc = _Word_DocOpen($oWord, $wordfilepath)
    If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFindReplace Example", _
            "Error opening '"&$wordfilepath&"'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
;~     *****************************************************************************
;~     Replace operation
;~     *****************************************************************************
;~     DEBUG!!!
    For $i = 0 To UBound($snrarray) - 1
        _Word_DocFindReplace($oDoc, $snrarray[$i][0], $snrarray[$i][1])
        If @error Then ConsoleWrite("Replace " & $snrarray[$i][0] & " with " & $snrarray[$i][1] & " - @error = " & @error & ", @extended = " & @extended & @CRLF)
    Next
    MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFindReplace Example", "Paragraph control character successfully replaced.")
    _Word_DocClose($oDoc)
    _Word_Quit($oWord)
EndFunc

WordReplace.docx content

Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
Sunday

 

1 person likes this

Share this post


Link to post
Share on other sites

#7 ·  Posted

Oh. fail. I did not see the Exit before MsgBox!!! FAIL.

Nevertheless: My word document also has an occurence of the word to replace within a textbox which is not being replaced. Is that not possible at the current time or do I need to search and replace text within textboxes in an other way?

Thank you again,
Weisgarnix

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Can you give us an example Doc and names you want to replace?

Edited by Subz
1 person likes this

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Hi Rani,

I attached my whole project. The first part works until the replacements, there it does not replace the appearances in the textbox.

Einladung_Test.docx

Einladung_Test.oft

liste.xlsx

 

logic.au3

Edited by Weisgarnix
replaced wrong file

Share this post


Link to post
Share on other sites

#10 ·  Posted

I can't test at the moment but IIRC the function only works on the "main text" of the document including tables. Header/Footer do not get processed. So this could be true for textboxes as well. Will need to check tomorrow. 

1 person likes this

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

#11 ·  Posted

Is the script for replacing the word document separate?  Or are you just using the function in the OP?

1 person likes this

Share this post


Link to post
Share on other sites

#12 ·  Posted

OP?

Share this post


Link to post
Share on other sites

#13 ·  Posted

OP = original post, actually it should have been post #3?  Its just that mailer.au3 doesn't have reference to Word replace?

1 person likes this

Share this post


Link to post
Share on other sites

#14 ·  Posted

Ah. Sorry, uploaded the really old version which was unable to personalize the attachments.
Replaced it with the current one! Thanks for the hint.

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

Okay, I will be able to live with the fact that it cannot replace strings within text boxes.

But I now have an other problem with the function _OL_ItemCreate. The error code says that the folder could not be accessed. The extended code says that the folder does not exist. But I dont know which folder they mean?

Edited by Weisgarnix
wrong language!

Share this post


Link to post
Share on other sites

#16 ·  Posted

At the moment I do not have spare time to look for a solution for the text box problem. Maybe next weekend :huh:

Can you please post the full _OL_ItemCreate statement you use?

1 person likes this

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

#17 ·  Posted

You can replace all strings within a document including Text Boxes using the following.

Func _pmailwordreplacetext($wordfilepath, $snrarray)
    ; Create application object
    Local $oWord = _Word_Create(False)
    If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFindReplace Example", _
        "Error creating a new Word application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    ; Open document
    Local $oDoc = _Word_DocOpen($oWord, $wordfilepath)
    If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFindReplace Example", _
            "Error opening '"&$wordfilepath&"'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    ; *****************************************************************************
    ; Replace operation
    ; *****************************************************************************
    ;DEBUG!!!
    ;_ArrayDisplay($snrarray)
    For $i = 0 To UBound($snrarray) - 1
        For $oStoryRange In $oDoc.StoryRanges
            _Word_DocFindReplace($oDoc, $snrarray[$i][0], $snrarray[$i][1], Default, $oStoryRange)
            While 1
                If IsObj($oStoryRange.NextStoryRange) Then
                    $oStoryRange = $oStoryRange.NextStoryRange
                    _Word_DocFindReplace($oDoc, $snrarray[$i][0], $snrarray[$i][1], Default, $oStoryRange)
                Else
                    ExitLoop
                EndIf
            WEnd
        Next
    Next
    ;MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFindReplace Example", "Paragraph control character successfully replaced.")
    ; Save document
    _Word_DocSave($oDoc)
    If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocSave Example", _
             "Error saving the Word document." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    ;MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocSave Example", "Document successfully saved as '" & _
    ;     $oDoc.FullName & "'")
    _Word_DocClose($oDoc)
    _Word_Quit($oWord)
EndFunc

 

1 person likes this

Share this post


Link to post
Share on other sites

#18 ·  Posted

You're syntax is wrong for _OL_ItemCreate

_OL_ItemCreate($oOL, $olMailItem, $oftfilepath)

It should be:

_OL_ItemCreate($oOL, $olMailItem, Default, $oftfilepath)

1 person likes this

Share this post


Link to post
Share on other sites

#19 ·  Posted

hi Subz.
Thank you for the help, Dont know why I've overseen that. I now added the Default but unfortunately still get the same error:

---------------------------
OutlookEX UDF: _OL_ItemCreate Example Script
---------------------------
Error creating the mail in folder. @error = 1, @extended = 4
---------------------------
OK   
---------------------------

Does somebody have an idea?

Here is the current source code:
 

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.14.1
 Author:         Armin Wiesmüller

 Script Function:
    providing functions for mass creating and sending personalized mails

#ce ----------------------------------------------------------------------------

#include <Excel.au3>
#include <File.au3>
#include <Array.au3>
#include <IE.au3>
#include <MsgBoxConstants.au3>
#include <Word.au3>
#include <AutoItConstants.au3>
#include "Source\OutlookEX.au3"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;Const $wdFormatPDF = 17

; Register the default Word.au3 COM Error Handler
;_WordErrorHandlerRegister()

; ###############################################################################
; ### T # E # S # T # - # A # R # E # A ### 5 # 1 ##### A # N # F # A # N # G ###
; ###############################################################################

; Überlegungen
; Anzahl Spalten = Anzahl Search and Replaces + 1
; Anzahl Zeilen = Anzahl Adressaten + 1

$adressatenliste = _pmailexcelreadfile(@ScriptDir&"\liste.xlsx", "A1:A10")
$searchandreplacearray = _pmailexcelreadfile(@ScriptDir&"\liste.xlsx", "B1:C10")
;_ArrayDisplay($adressatenliste)
;_ArrayDisplay($searchandreplacearray)

$j=0
While $j <= 8
    ;Local $aGrid[][] = [[$searchandreplacearray[0][0], [$searchandreplacearray[0][1]]], [$searchandreplacearray[$j+1][0], $searchandreplacearray[$j+1][1]]]
    Local $aGrid[2][2]
    $aGrid[0][0] = $searchandreplacearray[0][0]
    $aGrid[0][1] = $searchandreplacearray[$j+1][0]
    $aGrid[1][0] = $searchandreplacearray[0][1]
    $aGrid[1][1] = $searchandreplacearray[$j+1][1]
    FileCopy(@ScriptDir&"\Einladung_Test.docx", @TempDir&"\PMail\Einladung_Test.docx", $FC_OVERWRITE + $FC_CREATEPATH)
    FileCopy(@ScriptDir&"\Einladung_Test.oft", @TempDir&"\PMail\Einladung_Test.oft", 9)
    Sleep(2000)
    _ArrayDisplay($aGrid)
    _pmailwordreplacetext(@TempDir&"\PMail\Einladung_Test.docx", $aGrid)
    Sleep(2000)
    _pmailwordsaveaspdf(@TempDir&"\PMail\Einladung_Test.docx", @TempDir&"\PMail\Einladung_Test.pdf")
    Local $attacharray[1]=[@TempDir&"\PMail\Einladung_Test.pdf"]
    Sleep(2000)
    ; _pmailoutlookpreparemail($recipientadress, $subject, $snrarray, $oftfilepath, $attachmentsarray, $bcc="")
    _pmailoutlookpreparemail($adressatenliste[$j], "Exklusive Einladung zum Meet'n Greet für %$%Vorname%$% %$%NACHNAME%$%", $aGrid, @TempDir&"\PMail\Einladung_Test.oft", $attacharray, "some-mailadress@googlemail.com")
    Sleep(2000)
    _pmailoutlooksendmail(@TempDir&"\PMail\Einladung_Test.oft")
    Sleep(2000)
    DirRemove(@TempDir&"\PMail\", $DIR_REMOVE)
WEnd

; ###############################################################################
; ### # T # E # S # T # - # A # R # E # A ### 5 # 1 ########### E # N # D # E ###
; ###############################################################################

; ###############################################################################
; ### USER DEFINED FUNCTIONS - DO NOT CHANGE IF NOT SURE WHAT YOU'RE DOING!!! ###
; ###############################################################################

; #FUNCTION# ====================================================================================================================
; Name ..........: _pmailexcelreadfile
; Description ...: Reads the content of a defined range from an excelfile to an array
; Syntax ........: _readexcelfile($excelfilepath, $range)
; Parameters ....: $excelfilepath       - string: path to the excelfile. Will not be checked in this udf for existance!
;                  $range               - string: a range in the form "A1:B10".
; Return values .: $adressates          - array of strings: including the information read from the cells in the range of the excelfile.
; Author ........: Armin Wiesmüller
; Modified ......: 02.02.2017
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _pmailexcelreadfile($excelfilepath, $range)
    Local $oExcel =_Excel_Open()
    $data = _Excel_BookOpen($oExcel,$excelfilepath)
    $extracted = _Excel_RangeRead($data, Default, $range)
    _Excel_BookClose($data)
    ProcessClose("Excel.exe")
    ;If IsArray($adressates) Then _ArrayDisplay($adressates)
    If Not IsArray($extracted) Then
        MsgBox(16,"Error!","Excelfile could not be read to an array. Please check your excelfile and your range!")
    Else
        Return $extracted
    EndIf
EndFunc

; #FUNCTION# ====================================================================================================================
; Name ..........: _pmailwordreplacetext
; Description ...:
; Syntax ........: _pmailwordreplace($wordfilepath, $snrarray)
; Parameters ....: $wordfilepath        - string: path to the wordfile that will be modified.
;                  $snrarray            - array of strings: containing search ([x][0]) and corresponding replace [x][1] patterns.
; Return values .: None (works on the given file)
; Author ........: Armin Wiesmüller
; Modified ......: 02.02.2017
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _pmailwordreplacetext($wordfilepath, $snrarray)
    ; Create application object
    Local $oWord = _Word_Create(False)
    If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _pmailwordreplacetext", _
        "Error creating a new Word application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    ; Open document
    Local $oDoc = _Word_DocOpen($oWord, $wordfilepath)
    If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _pmailwordreplacetext", _
            "Error opening '"&$wordfilepath&"'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    ; *****************************************************************************
    ; Replace operation
    ; *****************************************************************************
    ;DEBUG!!!
    ;_ArrayDisplay($snrarray)
    For $i = 0 To UBound($snrarray) - 1
        For $oStoryRange In $oDoc.StoryRanges
            _Word_DocFindReplace($oDoc, $snrarray[$i][0], $snrarray[$i][1], Default, $oStoryRange)
            While 1
                If IsObj($oStoryRange.NextStoryRange) Then
                    $oStoryRange = $oStoryRange.NextStoryRange
                    _Word_DocFindReplace($oDoc, $snrarray[$i][0], $snrarray[$i][1], Default, $oStoryRange)
                Else
                    ExitLoop
                EndIf
            WEnd
        Next
    Next
    ;MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFindReplace Example", "Paragraph control character successfully replaced.")
    ; Save document
    _Word_DocSave($oDoc)
    If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _pmailwordreplacetext", _
             "Error saving the Word document." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    ;MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocSave Example", "Document successfully saved as '" & _
    ;     $oDoc.FullName & "'")
    _Word_DocClose($oDoc)
    _Word_Quit($oWord)
EndFunc

; #FUNCTION# ====================================================================================================================
; Name ..........: _pmailwordsaveaspdf
; Description ...:
; Syntax ........: _pmailwordsaveaspdf($wordfilepath, $pdffilepath)
; Parameters ....: $wordfilepath        - string: path and filename of the word-document to be converted.
;                  $pdffilepath         - string: path and filename of the destination file.
; Return values .: None (will create a new file in given destination)
; Author ........: Armin Wiesmüller
; Modified ......: 02.02.2017
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _pmailwordsaveaspdf($wordfilepath, $pdffilepath)
    ; Create application object
    Local $oWord = _Word_Create(False)
    ;If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFindReplace Example", _
    ;    "Error creating a new Word application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    ; Open document
    Local $oDoc = _Word_DocOpen($oWord, $wordfilepath)
    ;If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFindReplace Example", _
    ;   "Error opening '"&$wordfilepath&"'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    _Word_DocSaveAs($oDoc, $pdffilepath, $wdFormatPDF)
#cs     If @error And $WordComErrorNumber = -2147352567 Then
;         MsgBox(0, "Error", 'You first need to install the "2007 Microsoft Office Add-in: Microsoft Save as PDF".' & @CRLF & @CRLF & _
;                 "The download link will now be opened for you.")
;         _IECreate("http://www.microsoft.com/downloads/details.aspx?FamilyId=F1FC413C-6D89-4F15-991B-63B07BA5F2E5&displaylang=en", 0, 1, 0)
;     EndIf
 #CE
    _Word_DocClose($oDoc)
    _Word_Quit($oWord)
EndFunc

; #FUNCTION# ====================================================================================================================
; Name ..........: _pmailoutlookpreparemail
; Description ...:
; Syntax ........: _pmailoutlookpreparemail($recipientadress, $subject, $snrarray, $oftfilepath,
;                  $attachmentsarray[, $bcc = ""])
; Parameters ....: $recipientadress     - string: mail adress of the recipient - noch checked for containing an @ and at least one dot.
;                  $subject             - string: containing the subject including replacemant patterns.
;                  $snrarray            - array of strings: containing search ([x][0]) and corresponding replace [x][1] patterns.
;                  $oftfilepath   - string: path to the template file to fill up.
;                  $attachmentsarray    - array of strings: containing the paths to the files to be attached.
;                  $bcc                 - [optional] string: bcc-adress to send the mails to - e.g. for archive reason. Default is "".
; Return values .: None
; Author ........: Armin Wiesmüller
; Modified ......: 02.02.2017
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _pmailoutlookpreparemail($recipientadress, $subject, $snrarray, $oftfilepath, $attachmentsarray, $bcc="")
    ; Create a Copy of the file in the destination location
    ; OLD CODE - ADD BEFORE CALLING THIS FUNCTION: FileCopy($oftsourcefilepath, $oftdestinationfilepath, $FC_OVERWRITE + $FC_CREATEPATH)
    $snrarraysize=UBound($snrarray)
    $i=0
    While($i < $snrarraysize)
        _ReplaceStringInFile($oftfilepath, $snrarray[$i][0], $snrarray[$i][1])
        $subject = StringReplace($subject, $snrarray[$i][0], $snrarray[$i][1], 0, $STR_CASESENSE)
        $i+=1
    WEnd
    $oOL = _OL_Open()
    $oItem = _OL_ItemCreate($oOL, $olMailItem, Default, $oftfilepath)
    If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF: _OL_ItemCreate Example Script", "Error creating the mail in folder. @error = " & @error & ", @extended = " & @extended)
    ; Get current item
    $oItem0 = $oOL.ActiveInspector.CurrentItem
    If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF: $oOL.ActiveInspector.CurrentItem", "Error accessing current Inspector. @error = " & @error & ", @extended = " & @extended)
    ; Get Subject property
    $aProperties = _OL_ItemGet($oOL, $oItem0, Default, "Subject")
    If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF: _OL_ItemGet", "Error accessing current item. @error = " & @error & ", @extended = " & @extended)
    ; Modify Subject property
    $sSubject = $aProperties[1][1] & " - Changed Subject"
    _OL_ItemModify($oOL, $oItem, Default, "Subject=" & $sSubject)
    If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF: _OL_ItemModify", "Error accessing current item. @error = " & @error & ", @extended = " & @extended)
    ; add recipient and probably also bcc
    $oItem1 = _OL_ItemRecipientAdd($oOL, $oItem, Default, $olTo, $recipientadress)
    If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF: _OL_ItemRecipientAdd", "Error adding recipient. @error = " & @error & ", @extended = " & @extended)
    If $bcc <> "" Then
        $oItem2 = _OL_ItemRecipientAdd($oOL, $oItem, Default, $olBCC, $bcc)
        If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF: _OL_ItemRecipientAdd", "Error adding bbc recipient. @error = " & @error & ", @extended = " & @extended)
    EndIf
    If(UBound($attachmentsarray)>0) Then
        _OL_ItemAttachmentAdd($oOL, $oItem, Default, $attachmentsarray)
        If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF: _OL_ItemAttachmentAdd ", "Error adding attachment'. @error = " & @error & ", @extended = " & @extended)
    EndIf
    _OL_ItemSave($oOL, $oItem, Default, $oftfilepath, $olTemplate, 3)
EndFunc

; #FUNCTION# ====================================================================================================================
; Name ..........: _pmailoutlooksendmail
; Description ...:
; Syntax ........: _pmailoutlooksendmail($oftfilepath)
; Parameters ....: $oftfilepath         - string: path to the oft file to be sent.
; Return values .: None
; Author ........: Armin Wiesmüller
; Modified ......: 02.02.2017
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _pmailoutlooksendmail($oftfilepath)
    $oOL = _OL_Open()
    $oItem = _OL_ItemCreate($oOL, $olMailItem, $oftfilepath)
    ;If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF: _OL_ItemCreate Example Script", "Error creating a mail in folder 'Outlook-UDF-Test\TargetFolder\Mail'. @error = " & @error & ", @extended = " & @extended)
    ; Send the mail
    _OL_ItemSend($oOL, $oItem)
    ; Close Outlook connection
    _OL_Close($oOL)
EndFunc

 

Share this post


Link to post
Share on other sites

#20 ·  Posted

You should fix _OL_ItemCreate in function _pmailoutlooksendmail as well.

1 person likes this

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