• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
    • Password Reset
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

insert an image|VBA & Macros|Excel Forum|My Online Training Hub

You are here: Home / insert an image|VBA & Macros|Excel Forum|My Online Training Hub
Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search|Last Search Results
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumVBA & Macrosinsert an image
sp_PrintTopic sp_TopicIcon
insert an image
Avatar
GLENN STEPHENS

Active Member
Members
Level 0
Forum Posts: 5
Member Since:
August 3, 2021
sp_UserOfflineSmall Offline
1
August 3, 2021 - 10:48 pm
sp_Permalink sp_Print

 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.

Avatar
GLENN STEPHENS

Active Member
Members
Level 0
Forum Posts: 5
Member Since:
August 3, 2021
sp_UserOfflineSmall Offline
2
August 4, 2021 - 5:46 am
sp_Permalink sp_Print

Thought I would add some of the more technical items and what I am trying to do.

Avatar
Anders Sehlstedt
Eskilstuna, Sweden

VIP
Members


Trusted Members
Level 3
Forum Posts: 870
Member Since:
December 7, 2016
sp_UserOfflineSmall Offline
3
August 5, 2021 - 1:59 am
sp_Permalink sp_Print

Hello,

No Excel file attached, probably to big.

I would say that Excel is not the best tool for this scenario, but with VBA code it can be done. If you search in this forum you will find some posts with example code.

Br,
Anders

Avatar
GLENN STEPHENS

Active Member
Members
Level 0
Forum Posts: 5
Member Since:
August 3, 2021
sp_UserOfflineSmall Offline
4
August 5, 2021 - 11:41 am
sp_Permalink sp_Print sp_EditHistory

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

****************************************************

Avatar
GLENN STEPHENS

Active Member
Members
Level 0
Forum Posts: 5
Member Since:
August 3, 2021
sp_UserOfflineSmall Offline
5
August 7, 2021 - 10:46 pm
sp_Permalink sp_Print

This got moved but I have not received any answers.

Would love to know where I go next?

Avatar
GLENN STEPHENS

Active Member
Members
Level 0
Forum Posts: 5
Member Since:
August 3, 2021
sp_UserOfflineSmall Offline
6
August 8, 2021 - 5:51 am
sp_Permalink sp_Print

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

*************************************

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online:
Guest(s) 10
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 870
Purfleet: 412
Frans Visser: 346
David_Ng: 306
lea cohen: 219
A.Maurizio: 202
Jessica Stewart: 202
Aye Mu: 201
jaryszek: 183
Newest Members:
John Chisholm
vexokeb sdfg
John Jack
Malcolm Toy
Ray-Yu Yang
George Shihadeh
Naomi Rumble
Uwe von Gostomski
Jonathan Jones
drsven
Forum Stats:
Groups: 3
Forums: 24
Topics: 6212
Posts: 27236

 

Member Stats:
Guest Posters: 49
Members: 31888
Moderators: 3
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: MOTH Support, Velouria, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook
 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.