ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Dynamically insert a picture. (https://www.excelbanter.com/excel-programming/325754-dynamically-insert-picture.html)

Cherokee84

Dynamically insert a picture.
 
I would like to take a cell value and use it to dynamically enter in a
picture (really a Visio diagram).

For Example:
- If the cell A2s value was €œA423€
- It would look for the Visio diagram that corresponds to its name under
some folder structure like, €œ/some_folder/A423.vsd€
- Then insert that image/diagram into the Excel worksheet at a particular
area.

Does anyone have any ideas on doing this dynamically, if worse case would
like to have one macro that would insert multiple images, per each page in a
worksheet?


K Dales[_2_]

Dynamically insert a picture.
 
Here is code that will detect a change in cell A2 of any worksheet, will look
for the existence of the specified file, and will insert the picture on the
worksheet - put the path to the folder containing your pictures into
FolderPath and replace ".jpg" as needed:

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Dim TestRange As Range, FolderPath as String, PicFilePath As String
FolderPath = "C:\FolderName\SubFolderName\"
Set TestRange = Intersect(Sh.Range("A2"), Target)
If Not TestRange Is Nothing Then
PicFilePath = Folderpath & Sh.Range("A2").Value & ".jpg" ' REPLACE .jpg
IF NEEDED
If Dir(PicFilePath) = "" Then
MsgBox "File " & PicFilePath & " could not be found", vbExclamation,
"CANNOT INSERT PICTU"
Else
Sh.Range("B2").Select
Sh.Pictures.Insert PicFilePath
End If
End If
End Sub

(Written in Excel XP, cannot say if it works for earlier versions)
HTH! K Dales

"Cherokee84" wrote:

I would like to take a cell value and use it to dynamically enter in a
picture (really a Visio diagram).

For Example:
- If the cell A2s value was €œA423€
- It would look for the Visio diagram that corresponds to its name under
some folder structure like, €œ/some_folder/A423.vsd€
- Then insert that image/diagram into the Excel worksheet at a particular
area.

Does anyone have any ideas on doing this dynamically, if worse case would
like to have one macro that would insert multiple images, per each page in a
worksheet?



All times are GMT +1. The time now is 04:53 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com