VBA to insert a custom image

dpaton05

Well-known Member
Joined
Aug 14, 2018
Messages
2,375
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

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Just a thought, but have you considered adding the image to the Page footer instead of trying to fit it into the actual page ??

Code:
Sub MM1()
With ActiveSheet.PageSetup
    fNameAndPath = Application.GetOpenFilename(Title:="Select Signature To Be Imported")    
    .LeftFooterPicture.fileName = fNameAndPath
    .LeftFooter = "&G"
End With
End Sub
 
Last edited:
Upvote 0
I was just thinking it would be possible to measure the height of the image and if it won't fit in the section of several lines below the notes box to the bottom of the page, to have it inserted in the next page.
 
Upvote 0
Is there a setting in excel to stop an image being split over 2 pages?
 
Upvote 0
Just a thought, but have you considered adding the image to the Page footer instead of trying to fit it into the actual page ??

Code:
Sub MM1()
With ActiveSheet.PageSetup
    fNameAndPath = Application.GetOpenFilename(Title:="Select Signature To Be Imported")    
    .LeftFooterPicture.fileName = fNameAndPath
    .LeftFooter = "&G"
End With
End Sub

But if it gets pushed to the additional page, it will be at the bottom and I need it at the top.
 
Upvote 0
Also, isn't the page footer on every page, I need it just once at the end of the document.
 
Upvote 0
What if you insert a page break if below textbox 4 if there are only 6 or less rows to the end of the current page and then insert the picture at the top of the next page?
 
Upvote 0
Is there a setting in excel to stop an image being split over 2 pages?
Not that I'm aware of...otherwise we would have used it !!
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

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