VB and VBA Users Source Code: Changing the picture of an Image on an Excel worksheet
[
Home
|
Contents
|
Search
|
Reply
| Previous |
Next
]
VB/VBA Source Code
Changing the picture of an Image on an Excel worksheet
By:
Andrew Baker
Email (spam proof):
Email the originator of this post
Date:
Wednesday, May 16, 2001
Hits:
2507
Category:
VBA (Visual Basic for Applications)
Article:
The following routine demonstrates how to change the picture of an image control on an Excel worksheet: 'Purpose : Loads an image to an picture control on an Excel Worksheet 'Inputs : oShtLoad The sheet where the image is located. ' sImageName The name of the image ' 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 : Function LoadPictureToSheet(oShtLoad As Excel.Worksheet, sImageName As String, sPicturePath As String) As Boolean On Error GoTo ErrFailed If Len(Dir$(sPicturePath)) > 0 And Len(sPicturePath) > 0 Then 'File exists, try and load it Set oShtLoad.OLEObjects(sImageName).Object.Picture = LoadPicture(sPicturePath) LoadPictureToSheet = True End If Exit Function ErrFailed: Debug.Print Err.Description LoadPictureToSheet = False End Function 'Demonstration routine Sub Test() LoadPictureToSheet Sheets(1), "Image1", "D:\Test.jpg" End Sub
Terms and Conditions
Support this site
Download a trial version of the Excel Workbook Rebuilder