尝试保护工作簿中的特定工作表但出现40036错误

时间:2018-11-12 17:23:51

标签: excel vba excel-vba

我正在打开一个指定为wb的特定文件,它正在读取工作表,因此将我的msgbox作为检查,但是当我保护同一工作表时,会出现编译器错误。

我尝试了多种方法来完成此任务,但没有任何效果,例如激活特定的“首页”工作表以选择它等等,但是无济于事。

我要去哪里错了? 谢谢

    Dim Sht As Worksheet
    Dim wb As Workbook
    Dim LastRow As Long
    Dim WSName As String
    Dim URNName As String
    Dim lRow As Long

    Workbooks.Open Filename:= "\\Folder\1718 list of SD(s) trainees.xlsm"

    Worksheets("pivot").Activate

    LastRow = 240

    For i = 4 To 240

        WSName = Cells(i, 6)
        URNName = Cells(i, 7)

        ' Workbooks.Open Filename:="\\Folder\Annex G Usage\" & WSName & " " & URNName & " SD(s)17-18 Statement of Grant Usage.xlsm"
        Set wb = Workbooks.Open("\\Folder\Annex G Usage\" & WSName & " " & URNName & " SD(s)17-18 Statement of Grant Usage.xlsm")

        MsgBox " Name" & Cells(10, 3)

        ' wb.Sheets("Front Page").Activate

        ActiveSheet.Protect Password:="SOReadyToHelp", _
                            DrawingObjects:=True, _
                            Contents:=True, _
                            Scenarios:=True, _
                            AllowSorting:=True, _
                            AllowFiltering:=True, _
                            AllowUsingPivotTables:=True

        ActiveWorkbook.Save
        ActiveWindow.Close

    Next i

End Sub

0 个答案:

没有答案