2014-02-10 34 views
0

保護對象有什麼辦法來存儲在VBA中.protection對象,並使用存儲在對象的參數再使用它來保護表?使用在VBA

我知道這是可能存儲對象,但我不能用它來再次保護工作表。

我需要這個,因爲不同的表有不同的保護輪廓,我想在一個循環中使用這個。

Set wsp = workbookname.Sheets(sheetname).Protection 

,並再次保護工作表,我想用這樣的:

workbookname.Sheets(sheetname).Protect wsp 
+0

我不覺得有什麼。您將不得不求助於「Select Case」或「If」語句,以不同的方式保護工作簿中的不同工作表。 – L42

回答

0

,你可以如使用設置爲您的每個配置文件創建s類,例如。 HTH

' Class module SomeProtectionProfile 

Private m_password As Variant 
Private m_drawingObjects As Variant 
Private m_contents As Variant 
Private m_scenarios As Variant 
Private m_userInterfaceOnly As Variant 
Private m_allowFormattingCells As Variant 
Private m_allowFormattingColumns As Variant 
Private m_allowFormattingRows As Variant 
Private m_allowInsertingColumns As Variant 
Private m_allowInsertingRows As Variant 
Private m_allowInsertingHyperlinks As Variant 
Private m_allowDeletingColumns As Variant 
Private m_allowDeletingRows As Variant 
Private m_allowSorting As Variant 
Private m_allowFiltering As Variant 
Private m_allowUsingPivotTables As Variant 

Private Sub Class_Initialize() 
    m_password = "SomePsw1" 
    ' and others like m_drawingObjects, m_contents ... 
End Sub 

Public Sub Protect(sheetToProtect As Worksheet) 
    sheetToProtect.Protect Password:=m_password ' , ... and others 
End Sub 

' Standard module 

Sub main() 
    With New SomeProtectionProfile 
     .Protect workbookname.Sheets(sheetname) 
    End With 
End Sub 

enter image description here

+0

好吧,這指出我在正確的方向。謝謝。 是否有某種方式來獲得drawingobjects,情景和內容的狀態? – ApieVuist

+0

應該Worksheet.ProtectContents,ProtectScenarios和ProtectDrawingObjects只讀屬性。順便說一句,如果你喜歡答案標記爲接受...我會很高興的要點:-) – dee