VBA help for importing images from file

augejevgenij

New Member
Joined
Mar 3, 2021
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hello,

I just started to use VBA and would really appreciate if someone could help me out. I would like to view images according to a path stored in a database. The images should refresh if a value in a specific cell is changed. I already figured out how to import one image according to the database, which is connected to that specific cell through INDEX and MATCH formulas. Unfortunately my knowledge is not enough to write a code which allows to import several images at the same time. Also it seems like sometimes previous images wont get removed and a new image is getting imported on top of the old one. If there is no image at all or no matching path in the database, a run-time error is exposed.

Is it even possible to find a clean solution for my problem and import several images at the same time? I would be really thankful if somebody could lead me in the right direction and at least help me deal with the runtime errors. Huge thanks in advance!

Database:

image01.png


Screen + specific Cell (red):


image02.png


Code used to import first image:

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$CG$1" Then
    Shapes(1).Delete
    Pictures.Insert(ActiveSheet.Range("V21").Value).Select
    With Selection
        .Height = ActiveSheet.Range("V21:CI40").Height
        .Width = ActiveSheet.Range("V21:CI40").Width
        .Left = ActiveSheet.Range("V21").Left
        .Top = ActiveSheet.Range("V21").Top
    End With
    Range("C3").Select
End If
End Sub

The full file and images in a ZIP:

VBA help for importing images from file
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.

augejevgenij

New Member
Joined
Mar 3, 2021
Messages
2
Office Version
  1. 365
Platform
  1. Windows
The problem was solved by a kind user on Stackoverflow:


Thank You
 
Solution

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
63,649
Office Version
  1. 365
Platform
  1. Windows
Welcome to the MrExcel Message Board!

For future reference
Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 

Forum statistics

Threads
1,143,687
Messages
5,720,293
Members
422,275
Latest member
Maria95

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top