I am new to vba, and have been somewhat successful in some of the basics, but I am having trouble
getting the below code to work. I am trying to select a picture from file, then insert it in a range,
completely centered. I really have tried to make it work, and have tried the search function, but it
just isnt happening for me.
I would be very grateful if someone with knowledge could look at it and tell me where i zigged instead of zagged.
Thanks.
getting the below code to work. I am trying to select a picture from file, then insert it in a range,
completely centered. I really have tried to make it work, and have tried the search function, but it
just isnt happening for me.
I would be very grateful if someone with knowledge could look at it and tell me where i zigged instead of zagged.
Thanks.
VBA Code:
Private Sub CommandButton11_Click()
Dim fNameAndPath As Variant
Dim img As Picture
Set ws = Worksheets("Cover_Page")
fNameAndPath = Application.GetOpenFilename(Title:="Select Picture To Be Imported")
If fNameAndPath = False Then Exit Sub
Set img = Worksheets("Cover_Page").Pictures.Insert(fNameAndPath)
With img
'Resize Picture to fit in the range....
.Left = ActiveSheet.Range("B15").Left
.Top = ActiveSheet.Range("B15").Top
.Width = ws.("B15:I15").Width
.Height = ws.("B15:I33").Height
img.Top = cellLocation.Top + (cellLocation.Height / 2) - (myImage.Height / 2)
img.Left = cellLocation.Left + (cellLocation.Width / 2) - (myImage.Width / 2)
.Placement = 1
.PrintObject = True
End With
End Sub