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

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
The problem was solved by a kind user on Stackoverflow:


Thank You
 
Upvote 0
Solution
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.
 
Upvote 0

Forum statistics

Threads
1,214,594
Messages
6,120,436
Members
448,964
Latest member
Danni317

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
Back
Top