VBA Macro to Insert .jpg in to a worksheet

do17d0n

New Member
Joined
Apr 4, 2020
Messages
1
Office Version
  1. 365
Hello,

I am new to VBA Macro code writing.

Using a command button, I would like to insert a .jpg in to a worksheet. This .jpg would get pulled from a shared folder. The command would know to pull the correct .jpg using a matching cell name. And ideally, the .jpg would automatically get sized to fix an already sized cell box.

Please help with the code necessary to execute the above thought process.

Thank you!
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Why do you get when you recorded the macro? This would be your starting point
If would be a matter of of changing the macro to grab the file name from the cell (adding it to the shared folder path, a constant I guess in your problem) to create a full path so that the macro knows which file to insert
 
Upvote 0
Or:
Picture name without extension is in Cell L1. Change accordingly.
Change the code if it has the extension in Cell L1. Also change the code if it is a ".jpeg" extension.
Change the path to fit the actual.
Code:
Sub Maybe()
    ActiveSheet.Pictures.Insert("C:\Users\Rembrand\Pictures\My Pictures\" & Range("L1") & ".jpg").Name = "New Picture"
    With ActiveSheet.Shapes("New Picture")
        .LockAspectRatio = msoFalse
        .Left = Cells(1, 3).Left    '<---- Left side of Column C
        .Top = Cells(4, 1).Top    '<---- Top of Row 4
        .Height = Cells(20, 1).Top - Cells(4, 1).Top    '<---- Difference Row 20 and Row 4
        .Width = Cells(1, 12).Left - Cells(1, 3).Left    '<---- Difference Column 12 (= L) and 3 (= C)
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,817
Messages
6,121,720
Members
449,050
Latest member
MiguekHeka

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