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:
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
ActiveSheet.Pictures.Insert(FullFileName).Select
Selection.ShapeRange.LockAspectRatio = msoFalse
Selection.ShapeRange.Height = x
Selection.ShapeRange.Width = Y
Selection.ShapeRange.Top = Z
Selection.ShapeRange.Left = AA
“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.
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?