Inserting an image from the browse dialog box using vba

dpaton05

Well-known Member
Joined
Aug 14, 2018
Messages
2,373
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have made a spreadsheet for my supervisor and he wants the ability to insert a custom signature file at the bottom of a sheet using the browse dialogue box. I already have two buttons that enter a signature each. The signatures are in the right position.

Code:
Sub cmdJakeSig()
    ActiveSheet.Unprotect Password:="npssadmin"
        Dim sht As Worksheet
        Set sht = ActiveSheet
        Dim lr As Long
        'Find the last used row in Column A of target.  Change column as required
            lr = Sheets("NPSS_quote_sheet").Range("A" & Rows.Count).End(xlUp).Row + 4
            Sheets("sheet2").Shapes("ImgJ").Copy
            Sheets("NPSS_quote_sheet").Paste _
            Destination:=Worksheets("NPSS_quote_sheet").Range("A" & lr + 6)
    
    'ActiveSheet.Protect Password:="npssadmin"
End Sub

The code copies a set image from another sheet to the right spot. I want to be able to browse for an image and enter it in the same position on NPSS_quote_sheet without needing to enter it into sheet 2 and the copy it from sheet2. Could someone help me with the vba code please?
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Maybe something like this

Code:
Sub ChangeImage()
ActiveSheet.Unprotect Password:="npssadmin"
Dim lr As Long
lr = Sheets("NPSS_quote_sheet").Range("A" & Rows.Count).End(xlUp).Row + 4
 With Application.FileDialog(msoFileDialogFilePicker)
        .AllowMultiSelect = False
        .ButtonName = "Submit"
        .Title = "Select an image file"
        .Filters.Clear
        .Filters.Add "JPG", "*.JPG"
        
        If .Show = -1 Then
            Dim img As Object
            Set img = ActiveSheet.Pictures.Insert(.SelectedItems(1))
            'Position Image
            img.Left = 0
            img.Top = ActiveSheet.Range("A" & lr + 6).Top
            img.Width = 150
            img.Height = 150
        Else
            MsgBox ("Cancelled.")
        End If
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,705
Messages
6,173,985
Members
452,540
Latest member
haasro02

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