Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

Sheet Protection with VBA and Inserting Images

0

I have a macro to protect all sheets in a workbook as follow:

Sub protectsheets()
Dim wsheet As Worksheet
For Each wsheet In ActiveWorkbook.Worksheets
wsheet.Protect ("alex")
Next wsheet
End Sub
Sub unprotectsheets()
Dim wsheet As Worksheet
myPassword = InputBox("Enter Password")
While (myPassword <> "alex")
myPassword = InputBox("Enter Password")
Wend
For Each wsheet In ActiveWorkbook.Worksheets
wsheet.Unprotect (myPassword)
Next wsheet
End Sub

My question how can I allow edit object in the routine. The reason is that when sheet is protected i cannot paste picutres into the unlocked cells area, and i need that.

Thank you, your help will appreciated

Post Edited
Title: Title was not descriptive.
CODE Tags: You must add [CODE][/CODE] tags around your code! (click the CODE button to do this when creating a post)
Tags: Tags were updated to reflect the topic of the question.
Answer
Discuss

Answers

0

Hi, please surround your code with CODE tags next time!

You can protect the sheet like this:

ActiveSheet.Protect DrawingObjects:=False

DrawingObjects:=False is the addition that you are looking for.

In your code, change this line:

wsheet.Protect ("alex")

to

wsheet.Protect Password:="alex", DrawingObjects:=False
Discuss


Answer the Question

You must create an account to use the forum. Create an Account or Login