Jump to content

Error with _Word_DocFindReplace


Recommended Posts

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

Link to comment
Share on other sites

Can you please post the line where you call _Wird_DocFindReplace?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

 

Link to comment
Share on other sites

  • 3 weeks later...

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
Link to comment
Share on other sites

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

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

 

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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. 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

 

Link to comment
Share on other sites

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!
Link to comment
Share on other sites

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?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

 

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

You should fix _OL_ItemCreate in function _pmailoutlooksendmail as well.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...