My Macros will not work after I protect my document.

  • Thread starter Thread starter Samantha
  • Start date Start date
S

Samantha

Is there any way to make macros work once my document is protected? If so how?
 
If you are changing anything on the worksheet and the worksheet is protected
then you will get an error. You need to Unprotect the worksheet, run your
code, then Protect it again.

Sub Protect90()

Sheets("Sheet1").Unprotect "password"

'your code here

Sheets("Sheet1").Protect "password"

End Sub

Ryan
 
What?
Where would I put that? I have multiple macros on each sheet of my
workbook...am i supposed to put this in each of my macros? what will this
macro do?
 
In my experience, if you protect the workBOOK, macros will not run. They
should still run with a protected worksheet though.
 
No im protecting the workSHEET

mike said:
In my experience, if you protect the workBOOK, macros will not run. They
should still run with a protected worksheet though.
 
Try saving as file type 'macro enabled workbook' in the save as filetype
dropdown. That worked for me with a protected sheet with macros.
 
Anything you can not do manually on a protected spreadsheet will also not
work in a macro... The only exclusion to that rule is if you protected the
sheet in code and added the parameter UserInterfaceOnly:=True. At that point
macros will have some abilities that can not be done manually. That being
said UserInterfaceOnly is a bit hit and miss so it may not be worth doing.
 
Add that code at the beginning and the end of each macro. You need to do it
for each sheet you intend to modify. If you want to post one of your macros,
we can add the necessary code to show you what we mean...
 
Does an error pop up? If so, click "Debug". Then you will see a line at the
top of the procedure that looks something like "Sub Macro1()". Under that
line put this code:

Dim sh As Worksheet

For Each sh In Worksheets
sh.Unprotect
Next sh

'your macro syntax here

then, at the end of the procedure you need to put this:

For Each sh In Worksheets
sh.Protect
Next sh

End Sub

NOTE: If you entered a password when you protected the worksheet add "
Password:= "Your Password Here" directly next to sh.Unprotect and sh.Protect

Hope this helps!
 
Sub Create_New_Entry()

Rows("24:24").Select
Selection.Insert Shift:=xlDown
Range("E23:R23").Select
Selection.AutoFill Destination:=Range("E23:R24"), Type:=xlFillDefault
Range("B24").Select
End Sub
 
Sub Create_New_Entry()

Rows("24:24").Select
Selection.Insert Shift:=xlDown
Range("E23:R23").Select
Selection.AutoFill Destination:=Range("E23:R24"), Type:=xlFillDefault
Range("B24").Select
End Sub
 
Sub Create_New_Entry()

Activesheet.Unprotect

Rows("24:24").Select
Selection.Insert Shift:=xlDown
Range("E23:R23").Select
Selection.AutoFill Destination:=Range("E23:R24"), Type:=xlFillDefault
Range("B24").Select

Activesheet.Protect

End Sub
 
Mike

Is this a feature of Excel 2007?

In earlier version. macros will run on protected workBOOKS


Gord Dibben MS Excel MVP
 
sry for the off topic Samantha . . .

I was using 2007 when I found that my macro wouldn't run on a protected
workbook. It took me days to figure out what was goin wrong and several hours
in this forum - No one was able to help me.
 
Mike... did you ever find out what to do to be able to run macros on a
password protected workbook? Would appreciate your help before I go crazy!

Roger.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top