Insert Image VBA

pure vito

Board Regular
Joined
Oct 7, 2021
Messages
180
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I recorded this macro, I was hoping it would copy a part number typed into "E4" navigate to the folder with all the part images and then paste the number into the search bar and then paste the image onto my sheet this works fine,

But as you can see the part number is recorded into the macro meaning I will only ever see this part number image, and changing the part number in "E4" will not make a difference,

Is it possible to create a macro that will perform what I'm trying to achieve, assuming you can see what I'm trying to do 😅

Thanks all,

VBA Code:
Sub Macro2()
'
' Macro2 Macro
'

'
    Range("E4").Select
    Selection.Copy
    ActiveSheet.Pictures.Insert( _
        "C:\Users\vmapp1\OneDrive\OneDrive - JAGUAR LAND ROVER\Pictures\parts\M8E2-279A70-AA.png" _
        ).Select
    Selection.ShapeRange.ScaleWidth 0.2671568627, msoFalse, msoScaleFromTopLeft
    Selection.ShapeRange.ScaleHeight 0.2671568593, msoFalse, msoScaleFromTopLeft
    Selection.ShapeRange.IncrementLeft -169.5
    Selection.ShapeRange.IncrementTop 52.5
    Range("E6").Select
End Sub
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
So you want to write a valid and known picture name in E4 and have that picture inserted in E4; if this is correct try replacing your initial 3 lines with the following:
VBA Code:
    Range("E4").Select
'    Selection.Copy        'Useless, may be removed
    ActiveSheet.Pictures.Insert( _
        "C:\Users\vmapp1\OneDrive\OneDrive - JAGUAR LAND ROVER\Pictures\parts\" & Range("E4").Value & ".png").Select
In case you write the complete name & file extension in E4, then you have to remove that & ".png" from the instruction

Try...
 
Upvote 0
Solution
That works perfectly, thank you very much for taking the time, Champion!
 
Upvote 0

Forum statistics

Threads
1,215,092
Messages
6,123,063
Members
449,090
Latest member
fragment

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