VBA to insert picture

saekehoe

New Member
Joined
May 16, 2011
Messages
3
I am working on a macro to insert an electronic signature based on the password that the user inputs. I use the vlookup function to match the password to the image location. However, I am haing trouble getting the image to show up in the document. my vba code is below:

with this code i keep recieving the error: 1004 Unable to get the insert property of the picture class.

vb
Option Explicit
Private Sub cmdSignature1_Click()
Dim strPassword As String
Dim rngSigloc As Range
Dim varLocation As Variant
Dim rngSig1 As Range
Dim rngpassword As Range
Dim pfind As Range
Set rngSig1 = Range("signature1")
Set rngSigloc = Range("PasswordFind")
Set rngpassword = Range("a1")
Set pfind = Range("passwordfind")
strPassword = InputBox("Please enter your password")
Sheets("signature").Select
Range("A1").Select
ActiveCell.Value2 = strPassword
varLocation = Application.WorksheetFunction.VLookup(rngpassword, pfind, 2, False)
Debug.Print varLocation
Sheets("101 IR FORM").Select

rngSig1 = ActiveSheet.Pictures.Insert(varLocation).Select
Selection.ShapeRange.ScaleHeight 0.25, msoFalse, msoScaleFromTopLeft
Selection.ShapeRange.ScaleWidth 0.4, msoFalse, msoScaleFromTopLeft
Selection.ShapeRange.IncrementLeft 159#
Selection.ShapeRange.IncrementTop 2#

end sub

vb



Any help or suggestions would be greatly appreciated.
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
It may be able to be simplified, but this is the code I use for a series of reports I have:
Code:
Sub Signature()
User:   UserName = LCase(InputBox("Please enter username.", "Username", vbOKCancel))
        If UserName = "" Then Exit Sub
        If UserName = "'first user" Then
PWordJS:        Password = InputBox("Please enter password.", "Password", vbOKOnly)
                If Password = "" Then Exit Sub
                If Password = "'password" Then
                    Sheets("Home").Range("C27").Select
                    ActiveSheet.Pictures.Insert( _
                    "'location of picture/image" _
                    ).Select
                    Selection.ShapeRange.LockAspectRatio = msoFalse
                    Selection.ShapeRange.Width = 168#
                    Selection.ShapeRange.Height = 15#
                    Selection.ShapeRange.IncrementTop 2.25
                    Selection.ShapeRange.IncrementLeft 0.75
                Else:
                    MsgBox "You have entered an incorrect password.", vbOKOnly, "Incorrect Password"
                    GoTo PWordJS
                End If
        
        ElseIf UserName = "'2nd user" Then
PWordDM:        Password = InputBox("Please enter password.", "Password", vbOKOnly)
                If Password = "" Then Exit Sub
                If Password = "2nd password" Then
                    Sheets("Home").Range("C27").Select
                    ActiveSheet.Pictures.Insert( _
                    "'location of 2nd image" _
                    ).Select
                    Selection.ShapeRange.LockAspectRatio = msoFalse
                    Selection.ShapeRange.Width = 168#
                    Selection.ShapeRange.Height = 15#
                    Selection.ShapeRange.IncrementTop 2.25
                    Selection.ShapeRange.IncrementLeft 0.75
                Else:
                    MsgBox "You have entered an incorrect password.", vbOKOnly, "Incorrect Password"
                    GoTo PWordDM
                End If
        Else:
            MsgBox "You have entered an incorrect user name.", vbOKOnly, "Incorrect User Name"
            GoTo User
        End If
End Sub
 
Upvote 0
klarowe,

When i put in my file location, I get the error again... what could be causing this?

Thanks,

Scott
 
Upvote 0

Forum statistics

Threads
1,224,503
Messages
6,179,135
Members
452,890
Latest member
Nikhil Ramesh

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