Macros don't work when sheet is protected. Running macro returns run-time error 1004

后端 未结 2 770
自闭症患者
自闭症患者 2021-01-15 04:10

I have three macros in my workbook that work fine. However, when I protect any of the worksheets, they stop to work and I get a run-time error 1004.

I

2条回答
  •  别那么骄傲
    2021-01-15 04:30

    help for macro beginners:

    if you are using a button to run a macro, include the following inside sub buttonclick()

    Dim sh As Worksheet
    
    Dim yourPassword As String
    
        yourPassword = "whatever password you like"
    
       For Each sh In ActiveWorkbook.Worksheets
            sh.Unprotect Password:=yourPassword
    

    "now enter your macro which needs to be run

    ,at the end , before end sub paste the below line

    For Each sh In ActiveWorkbook.Worksheets
            sh.Protect Password:=yourPassword
        Next sh
    

提交回复
热议问题