2016-08-03 215 views
-4

對我有一些代碼,我使用VBA錄音機編寫,但我想在開始時添加解鎖表單,然後在表尾鎖定表單。用VBA鎖定和解鎖

私人小組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' 
+0

那麼爲什麼不你只需添加它?你有什麼問題? –

+0

你的問題是什麼? –

+0

[VBA事件 - 解鎖受保護工作表中的單元格,如果選中]的可能重複(http://stackoverflow.com/questions/27332602/vba-event-unlock-cell-in-protected-sheets-if-selected) – DragonSamu

回答

-1

完成它!

私人小組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 

末次