[英]macro over protected and shared worksheet excel
我在excel 2012中有一個共享且受保護的工作表。(受保護但沒有密碼)我寫了這個宏:
Private Sub CommandButton1_Click()
ActiveSheet.Unprotect
Range("B4:K38").Select
Selection.Sort Key1:=Range("D4"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
'cells I don't want to be protect (to be user-editable)
Range("B4:K38").Locked = False
'protecting the sheet, and all the other cells will be protected
Protect UserInterfaceOnly:=True
End Sub
但是,每次使用此宏時,我都會收到一條消息,告訴我保護方法存在錯誤。
我究竟做錯了什么?
試試看,未經測試,因為在移動設備上
而不是僅使用protect userinterfaceonly:=true
with activesheet
.EnableSelection = xlUnlockedCells
.Protect UserInterfaceOnly:=True
End With
同樣使用UserInterfaceOnly,您無需取消保護工作表即可使用vba對其進行編輯。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.