锁定&使用VBA

时间:2016-08-03 11:27:26

标签: vba

我有一些使用VBA刻录机编写的代码,但我想在开头添加解锁表,然后在最后锁定表。

Private Sub CommandButton1_Click()

' ' New_Risk_4宏     ActiveSheet.UsedRange     '重置最后一个活动单元格'

Sheets("Risk Template").Select
'Looks at the risk template sheet'

ActiveCell.Rows("1:7").EntireRow.Select
ActiveCell.Offset(0, 4).Range("A1").Activate
'selects everything within the range'

Selection.Copy
'Copies to clipboard'

Sheets("Risk Input Sheet").Select
'Switches back to Risk Input sheet'

ActiveCell.SpecialCells(xlLastCell).Select
'Selects last active cell'

ActiveCell.Offset(1, 0).Rows("1:1").EntireRow.Select
'Selects row with last active cell'

ActiveSheet.Paste
'Paste to select row'

1 个答案:

答案 0 :(得分:-1)

完成它!!

Private Sub CommandButton1_Click()

ActiveSheet.Unprotect “ 'New_Risk_4宏     ActiveSheet.UsedRange     '重置最后一个活动单元格'

Sheets("Risk Template").Select
'Looks at the risk template sheet'

ActiveCell.Rows("1:7").EntireRow.Select
ActiveCell.Offset(0, 4).Range("A1").Activate
'selects everything within the range'

Selection.Copy
'Copies to clipboard'

Sheets("Risk Input Sheet").Select
'Switches back to Risk Input sheet'

ActiveCell.SpecialCells(xlLastCell).Select
'Selects last active cell'

ActiveCell.Offset(1, 0).Rows("1:1").EntireRow.Select
'Selects row with last active cell'

ActiveSheet.Paste
'Paste to select row'

ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
    , AllowFormattingCells:=True, AllowFormattingColumns:=True, _
    AllowFormattingRows:=True, AllowInsertingColumns:=True, AllowInsertingRows _
    :=True, AllowInsertingHyperlinks:=True, AllowDeletingColumns:=True, _
    AllowDeletingRows:=True, AllowSorting:=True, AllowFiltering:=True, _
    AllowUsingPivotTables:=True

End Sub