Can't Import Images into Protected Excel Workbook


I have protected a excel workbook that needs to import images into a worksheet of this protected workbook to print in a report.

After I have selected the image I want to import into the sheet I get the following errors:
Error trying to load pic

I have a button that runs the following code to insert a image:
Sub ImageInsertion()
Dim x As Long
Dim Y As Long
Dim Z As Long
Dim AA As Long
Dim FullFileName As String
x = Selection.Height
Y = Selection.Width
Z = Selection.Top
AA = Selection.Left
FullFileName = Application.GetOpenFilename()
Select Case FullFileName
Case Is = False
Exit Sub
End Select
Selection.ShapeRange.LockAspectRatio = msoFalse
Selection.ShapeRange.Height = x
Selection.ShapeRange.Width = Y
Selection.ShapeRange.Top = Z
Selection.ShapeRange.Left = AA

End Sub`

“Error: access denied” is because you configured XLS Padlock to prevent access to the VBA editor. Excel wanted to show the VBA editor to show you the error in your code.

Thank you for the reply…
Is there a reason why it does not want to allow images to be imported into the complied workbook?

There are no errors when inserting images in the original excel workbook using the above vba code. The error only happens in the complied workbook

I compiled the workbook again to allow VBA errors to show, and this is the errors it gave:

Can you insert a MsgBox to show the value of FullFilename? And post the result here?

Sorry can you please advise how to do this? I am new to VBA

Just before ActiveSheet.Pictures… add this:
MsgBox FullFilename

Thanks this is what the MsgBox says

Looks like the workbook may be protected against import. Did you enter a password to lock the workbook or protect it against changes before compiling it?

The workbook is not protected but the sheet where the pictures must be imported to is protected to prevent the user from changing and deleting other parts of the sheet. The cells where the images are inserted into are not locked.

I removed the password from the sheet and compiled the workbook again and now I can import images now, but now the sheet is not protected and therefor the user can change and delete everything else on the sheet so the sheet actually does need to be password protected as mentioned above.

Is there anything that I am missing or that I should do to have the sheet password protected but also be able to import images into the unlocked cells of the sheet?

1 Like

Are you using this option?

You need to allow editing shape at where you enter your password to protect the sheet.