Excel VBA Error - Unable to get the Insert property of the Picture Class

Jords998

New Member
Joined
Nov 29, 2021
Messages
6
Office Version
  1. 365
Platform
  1. Windows
Hi all,

Hoping somebody can help.

This is my first time using VBA in a project & I'm not very familiar with it so I will need things explaining in a little more detail.

I have the below subs - Sub 1 is to use a button to select an image & to insert the file path into the table. The sub 2 should then display the image in a selected cell (M8). I keep getting the above error, at first I only had the problem when the workbook was protected, so I have added a work around. Since then I cannot select a cell containing a file path without getting the error. When selecting debug, it takes me to the line highlighted in red.

Any idea's on how I can fix this.

Sub 1:

Sub Cont_Attachthum()
Dim PicFile As FileDialog
With Sheet1
Set PicFile = Application.FileDialog(msoFileDialogFilePicker)
With PicFile
.Title = "Select a Contact Picture"
.Filters.Add "All Picture Files", ".jpg,*jpeg,*.gif,*.png,*bmp,*tiff", 1
If .Show <> -1 Then GoTo NoSelection
Sheet1.Range("Q11").Value = .SelectedItems(1) 'Put file name in Q11
End With
If .Range("B10").Value = False Then .Range("N" & Sheet1.Range("B9").Value).Value = .Range("Q11").Value
Cont_DisplayThumb

NoSelection:
End With
End Sub

Sub 2:

Sub Cont_DisplayThumb()
Dim PicPath As String
With Sheet1
On Error Resume Next
ActiveSheet.Protect Contents:=False
.Shapes("ThumbPic").Delete 'Delete thumbnail pic if any
On Error GoTo 0
PicPath = .Range("Q11").Value 'Picture Path
With .Pictures.Insert(PicPath)
With .ShapeRange
.LockAspectRatio = msoTrue
.Height = 80
.Name = "ThumbPic"
End With
End With
With .Shapes("ThumbPic")
.Left = Sheet1.Range("M8").Left
.Top = Sheet1.Range("M8").Top
.IncrementTop -35
End With
ActiveSheet.Protect Contents:=True
End With 'End Sheet1
End Sub
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
79,875
Office Version
  1. 365
Platform
  1. Windows
You need to unprotect the sheet, rather than protect it
VBA Code:
On Error Resume Next
.Unprotect
.Shapes("ThumbPic").Delete 'Delete thumbnail pic if any
On Error GoTo 0
 
Solution

Jords998

New Member
Joined
Nov 29, 2021
Messages
6
Office Version
  1. 365
Platform
  1. Windows
Thank you! Can't believe I missed that!
You need to unprotect the sheet, rather than protect it
VBA Code:
On Error Resume Next
.Unprotect
.Shapes("ThumbPic").Delete 'Delete thumbnail pic if any
On Error GoTo 0
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
79,875
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback.
 

Forum statistics

Threads
1,181,955
Messages
5,932,940
Members
436,869
Latest member
ABGTH

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
Top