VBA to insert a custom image

dpaton05

Well-known Member
Joined
Aug 14, 2018
Messages
2,352
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have code to insert a set image. Could someone tell me how to alter it so it can insert a custom image please?

Code:
Sub cmdJakeSig()
    Dim shp As Shape
    Set shp = ThisWorkbook.Worksheets("sheet1").Shapes("textbox4")
        Sheets("Sheet2").Shapes("ImgJ").Copy
        Sheets("sheet1").Paste Destination:=Sheets("sheet1").Cells(1, 1)
        Selection.Top = shp.Top + shp.Height + "50"
    'ActiveSheet.Protect Password:=""
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.
Shapes("ImgJ").Copy

What is this Dave ??
Are you copying and pasting Textbox4 or the picture "ImgJ" ??
 
Last edited:
Upvote 0
I think this is what you are trying to do ??
At least it should get you started
Code:
Sub MM1()
Dim fNameAndPath As Variant
Dim img As Picture
fNameAndPath = Application.GetOpenFilename(Title:="Select Picture To Be Imported")
If fNameAndPath = False Then Exit Sub
    Set img = ActiveSheet.Pictures.Insert(fNameAndPath)
    With img
       .Left = Sheets("sheet1").Cells(1, 1)
       .Top = Sheets("sheet1").Cells(1, 1)
    End With
End Sub
 
Upvote 0
What is this Dave ??
Are you copying and pasting Textbox4 or the picture "ImgJ" ??

ImgJ is the image I am pasting. It is stored on another sheet. I am putting it below textbox4 on sheet1.
 
Upvote 0
Thanks Michael,

That worked, just put the image in the centre over 2 pages. I need it left aligned on the first page.

Here is my code.

Code:
Dim fNameAndPath As Variant
Dim img As Picture, shp As Shape
Set shp = ThisWorkbook.Worksheets("sheet1").Shapes("textbox4")

fNameAndPath = Application.GetOpenFilename(Title:="Select Picture To Be Imported")
If fNameAndPath = False Then Exit Sub
    Set img = Worksheets("sheet1").Pictures.Insert(fNameAndPath)
    With img
       .Top = shp.Top + shp.Height + "50"
    End With

Thanks.
 
Upvote 0
I worked it out Michael, just added .left = "0" to the end of the with block.

Thanks
 
Upvote 0
How could I change the code so if the image was split between 2 pages, it would move the image to the second page?
 
Upvote 0
What is the relationship between txtbox 4 and the inserted shape ??
Why not simply place the new image

Code:
Sub MM1()
Dim fNameAndPath As Variant
Dim img As Picture, shp As Shape
Set shp = Worksheets("sheet1").Shapes("textbox 4")
fNameAndPath = Application.GetOpenFilename(Title:="Select Picture To Be Imported")
If fNameAndPath = False Then Exit Sub
    Set img = Worksheets("sheet1").Pictures.Insert(fNameAndPath)
    With img
       .Left = 0
       .Top = shp.Top + shp.Height + 50
    End With
End Sub
 
Upvote 0
What is the relationship between txtbox 4 and the inserted shape ??

Textbox4 is a notes text box and the inserted image is a signature that must be a set distance from the bottom of the notes.
 
Upvote 0

Forum statistics

Threads
1,213,561
Messages
6,114,315
Members
448,564
Latest member
ED38

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