# Function Reference

# _Word_DocPictureAdd

Adds a picture to the document

#include <Word.au3>
_Word_DocPictureAdd ( $oDoc, $sFilePath [, $bLinkToFile = False [, $bSaveWithDocument = False [, $oRange = 0]]] )

## Parameters

$oDoc | Word document object
$sFilePath | The path and file name of the picture
$bLinkToFile | [optional] Specifies whether to link the picture to the file from which it was created. True - Link the picture to the file from which it was created False - Make the picture an independent copy of the file (default)
$bSaveWithDocument | [optional] Specifies whether to save the linked picture with the document. True - Save the linked picture with the document False - Do not save the linked picture with the document (default)
$oRange | [optional] The location where the picture will be placed in the text. Can be 0 (the picture is placed automatically) or any range object (default = 0)

## Return Value

Success: | a variable pointing to the shape object
Failure: | 0 and sets the @error flag to non-zero.
@error: | 1 - $oDoc is not an object 2 - The specified picture does not exist 3 - Error occurred when adding the specified picture. @extended is set to the COM error code 4 - $oRange is not 0 but is not a range object

## Example

### Example 1

    #include "Extras\HelpFileInternals.au3"

    #include <MsgBoxConstants.au3>
    #include <Word.au3>

    ; Create application object
    Local $oWord = _Word_Create()
    If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocPictureAdd Example", _
            "Error creating the Word application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    ; Open the test document
    Local $oDoc = _Word_DocOpen($oWord, _Extras_PathFull("Test.doc"), Default, Default, True)
    If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocPictureAdd Example", _
            "Error opening '.\Extras\Test.doc'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

    ; Insert a picture after the fourth word of the document
    ; Set the range as insert marker after the 4th word
    Local $oRange = _Word_DocRangeSet($oDoc, -1, Default, 4, Default, 4)
    _Word_DocPictureAdd($oDoc, _Extras_PathFull("Screenshot.png"), Default, Default, $oRange)
    If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocPictureAdd Example", _
            "Error adding the picture to the document" & @CRLF & " @error = " & @error & ", @extended = " & @extended)
    MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocPictureAdd Example", _
            "Picture has successfully been added after word 4 in the document.")

### Example 2

    #include "Extras\HelpFileInternals.au3"

    #include <MsgBoxConstants.au3>
    #include <Word.au3>

    ; Create application object
    Local $oWord = _Word_Create()
    If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocPictureAdd Example", _
            "Error creating the Word application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    ; Open the test document
    Local $oDoc = _Word_DocOpen($oWord, _Extras_PathFull("Test.doc"), Default, Default, True)
    If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocPictureAdd Example", _
            "Error opening '.\Extras\Test.doc'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

    ; Add a picture to the end of the document
    ; Set the range as insert marker to the end of the document
    Local $oRange = _Word_DocRangeSet($oDoc, -2)
    _Word_DocPictureAdd($oDoc, _Extras_PathFull("Screenshot.png"), Default, Default, $oRange)
    If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocPictureAdd Example", _
            "Error adding the picture to the document." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocPictureAdd Example", _
            "Picture has successfully been added at the end of the document.")