VB and VBA Users Source Code: Changing the picture of an Image object on a Word Document
[
Home
|
Contents
|
Search
|
Reply
|
Previous
| Next ]
VB/VBA Source Code
Changing the picture of an Image object on a Word Document
By:
Andrew Baker
Email (spam proof):
Email the originator of this post
Date:
Tuesday, August 28, 2001
Hits:
1576
Category:
VBA (Visual Basic for Applications)
Article:
Below is the equivalent code to dynamically load an image to a word document. Option Explicit 'Purpose : Loads an image to an picture control in a Word document. 'Inputs : oDoc The document where the image is located. ' sImageName The name of the image in the document. ' sPicturePath The path to the image file to load. 'Outputs : Returns True if successfully loaded the image. 'Author : Andrew Baker 'Date : 25/03/2001 'Notes : Requires Word 2000. Function LoadPictureToDocument(oDoc As Document, sImageName As String, sPicturePath As String) As Boolean Dim oPic As Object On Error GoTo ErrFailed If Len(Dir$(sPicturePath)) > 0 And Len(sPicturePath) > 0 Then 'Picture file exists. 'Get reference to picture Set oPic = CallByName(oDoc, sImageName, VbGet) 'Load picture Set oPic.Picture = LoadPicture(sPicturePath) 'Release reference Set oPic = Nothing 'Return success code LoadPictureToDocument = True End If Exit Function ErrFailed: Debug.Print "Error in LoadPictureToDocument: " & Err.Description LoadPictureToDocument = False End Function 'Demonstration routine Sub Test() LoadPictureToDocument ActiveDocument, "imgSig1", "c:\a.bmp" End Sub
Terms and Conditions
Support this site
Download a trial version of the Excel Workbook Rebuilder