Active Member
August 3, 2021
am a Home Inspector in the US and I take a lot of photos for of homes for reports. I have used your Data Validation method and it works wonderfully. Now I am to the point where I need to insert a photo based on a typed value in the cell and it pulls the photo in from the working folder.
In PhotoTable[@Name] is where I type the value of the photograph name, i.e. 20210802_Image
From there I already have a cell that creates the file path of where the photo resides, i.e. C:\working\photos\20210802_Image.jpg
Next I am wanting to automatically use:
<table><img src="C:\working\photos\20210802_Image.jpg" width="300" height="200" >
I have 188 individual cells and Data Validation INDIRECT that I have painstaking typed in. Any assistance would be wonderful.
Excel: Office 365 for Business
OS: Windows 10
I have attached the excel file I am using and I know there is a lot of info.
VIP
Trusted Members
December 7, 2016
Active Member
August 3, 2021
So I know have VB code that works wonderfully, inserts the photo every time in the correct cells based on the Filename. The next issue, and I have search for hours is the VB code to rename the "Name Box" object of the photo based on a Cell Value.
Selection.ShapeRange.Name = "Picture 275754"
Selection.Name = "Picture_1"
Picture 275754 = the name excel creates when it inserts the object
Picture_1 = the name I need it to be
Again I have 188 photos that get inserted and sized at a specific cell in a single worksheet.
*********** Here is what I have so far ********
Private Sub Button6_Click()
Worksheets("Photos").Cells(1, 1).Select
Dim insp_pic As Picture
Dim pic_location As String
Dim pic_name As String
Dim pic_indirect As String
Dim pic_image As String
ActiveSheet.Pictures.Delete
For i = 2 To 189
pic_name = Worksheets("Photos").Cells(i, 3).Value
pic_location = Worksheets("Photos").Cells(i, 7).Value
With Worksheets("Photos").Cells(i, 4)
Rem Get Photos
Set insp_pic = ActiveSheet.Pictures.Insert(pic_location)
insp_pic.Top = .Top
insp_pic.Left = .Left
insp_pic.ShapeRange.LockAspectRatio = msoFalse
insp_pic.Placement = xlMoveAndSize
insp_pic.ShapeRange.Width = 225
insp_pic.ShapeRange.Height = 150
Rem Assign INDIRECT to ImageName
pic_indirect = Worksheets("Photos").Cells(i, 2).Value
ActiveWorkbook.Names(pic_indirect & "_dv").Delete
ActiveWorkbook.Names.Add Name:=pic_indirect & "_dv", RefersToR1C1:= _
"=INDIRECT(Photos!" & pic_indirect & ")"
ActiveWorkbook.Names(pic_indirect & "_dv").Comment = ""
Rem Rename Picture ******** Current Stuck Point **********
'Selection.ShapeRange.Name = "Picture 275754"
'Selection.Name = "Picture_1"
Rem Assign DV routine to Picture ****** This is giving me an error as well ********
'ActiveSheet.Shapes.Range(Array("Picture_1")).Select
'Picture_1 = Photo1_dv
End With
Next
Worksheets("Photos").Cells(1, 1).Select
End Sub
****************************************************
Active Member
August 3, 2021
Well here is the solution. It is not pretty, but it works. Would love to be able to streamline the process and to center the photos in the cell. But I guess that is the next project.
*******************************
Sub ImageButton1_Click()
Worksheets("Photos").Cells(2, 4).Select
Dim insp_pic As Picture
Dim pic_name As String
Dim pic_location As String
Dim pic_indirect As String
Dim pic_profile As String
ActiveSheet.Pictures.Delete
For i = 2 To 189
pic_name = Worksheets("Photos").Cells(i, 3).Value
pic_location = Worksheets("Photos").Cells(i, 7).Value
pic_indirect = Worksheets("Photos").Cells(i, 2).Value
pic_profile = Worksheets("Photos").Cells(i, 8).Value
pic_range = Worksheets("Photos").Cells(i, 4).Value
With Worksheets("Photos").Cells(i, 4)
Rem Get Photos
Set insp_pic = ActiveSheet.Pictures.Insert(pic_location)
insp_pic.ShapeRange.LockAspectRatio = msoFalse
insp_pic.Left = .Left + 5
insp_pic.Top = .Top + 4.5
insp_pic.Placement = xlMoveAndSize
insp_pic.ShapeRange.Width = 220
insp_pic.ShapeRange.Height = 145
Rem Set Profile Cell
ActiveWorkbook.Names.Add Name:=pic_profile, RefersToR1C1:=(Worksheets("Photos").Cells(i, 4))
Rem Define INDIRECT
ActiveWorkbook.Names.Add Name:=pic_profile & "_DV", RefersToR1C1:= _
"=INDIRECT(" & pic_indirect & ")"
Rem Rename Photo
'ActiveSheet.Shapes.Range(Array("")).Select
Selection.Formula = "=" & pic_profile & ""
End With
Next
'Rem Macro Complete
Worksheets("Photos").Cells(1, 1).Select
End Sub
*************************************
1 Guest(s)