返回列表 上一主題 發帖

一個保護問題,

回復 1# 317
將資料庫(字體顏色設與儲存格顏色同色) 設定資料庫保護時 不勾選 使用者可使用的選項
Sheets("資料頁").Protect Password:="1234", DrawingObjects:=True, Contents:=True, Scenarios:=True
在停用巨集時 資料頁便有保護了

TOP

回復 8# 317
所設定保護的密碼

TOP

本帖最後由 GBKEE 於 2010-12-9 20:18 編輯

回復 10# 317
你這圖片2是專案設定密碼用的,必需用手動的,無法用vba操作的
Sheets("資料頁").Protect Password:="1234", DrawingObjects:=True, Contents:=True, Scenarios:=True
上式是檔案中 工作表名為"資料頁"的設定保護的程式碼,且設立密碼為"1234"
先前告訴你將資料頁的字體顏色與儲存格的底色 顏色設為同樣顏色.
如關閉檔案時 執行此程式碼, 可預防再度開啟檔案, 如停用巨集時且資料頁沒隱藏.將不會暴露資料頁的內容

TOP

本帖最後由 GBKEE 於 2010-12-24 21:28 編輯

回復 14# 317
活頁簿設立開啟密碼,旁人無法開啟.

TOP

回復 17# 周大偉
如下圖 選取後 輸入密碼即可

TOP

回復 19# 周大偉
1.將程式碼貼於 ThisWorkbook,  專案的屬性->保護  勾選鎖定專案, 輸入密碼
2.活頁簿另存檔案指令 -> 工具-> 一般選項  輸入活頁簿保護密碼
  1. Option Explicit
  2. Private Const 密碼 = "1234"
  3. Private Const 字體顏色 = 1
  4. Private Const 保護色 = 2    '可自行修改
  5. Dim Answer$
  6. Private Sub Workbook_Open()
  7.     Sheets_Protect
  8.     Answer_Pass
  9. End Sub
  10. Private Sub Workbook_BeforeClose(Cancel As Boolean)
  11.     Sheets_Protect
  12.     Save
  13. End Sub
  14. Private Sub Workbook_SheetActivate(ByVal Sh As Object)
  15.     Answer_Pass
  16. End Sub
  17. Private Sub Workbook_SheetDeactivate(ByVal Sh As Object)
  18.      My_UnProtect (IIf(Answer = 密碼, True, False))
  19. End Sub
  20. Private Sub Sheets_Protect()
  21.     Dim Sh As Worksheet
  22.     For Each Sh In Sheets
  23.         With Sh
  24.         .Unprotect 密碼
  25.         .Cells.Font.ColorIndex = 保護色
  26.         .Cells.Interior.ColorIndex = .Cells.Font.ColorIndex
  27.         .EnableSelection = xlNoSelection
  28.         .Protect PassWord:=密碼, DrawingObjects:=True
  29.         End With
  30.     Next
  31. End Sub
  32. Private Sub My_UnProtect(Y As Boolean)
  33.     Application.ScreenUpdating = False
  34.     With ActiveSheet
  35.         .Unprotect 密碼
  36.         If Y = True Then
  37.             .Cells.Font.ColorIndex = 字體顏色
  38.             .Cells.Interior.ColorIndex = xlNone
  39.             Application.CommandBars.FindControl(ID:=30029).Enabled = True
  40.         Else
  41.             .Cells.Font.ColorIndex = 保護色
  42.             .Cells.Interior.ColorIndex = .Cells.Font.ColorIndex
  43.             .EnableSelection = xlNoSelection
  44.             .Protect PassWord:=密碼, DrawingObjects:=True
  45.             Application.CommandBars.FindControl(ID:=30029).Enabled = False
  46.         End If
  47.     End With
  48.     Application.ScreenUpdating = True
  49. End Sub
  50. Private Sub Answer_Pass()
  51.     If Answer <> 密碼 Then
  52.         If InputBox("密碼??", "輸入密碼") = 密碼 Then Answer = 密碼
  53.     End If
  54.     My_UnProtect (IIf(Answer = 密碼, True, False))
  55. End Sub
複製代碼

TOP

本帖最後由 GBKEE 於 2010-12-25 20:42 編輯

回復 21# 周大偉
Application.CommandBars.FindControl(ID:=30029).Enabled = False
Control 指令 -> 保護(ID:=30029) 的使用(停止= False)
每一Control 有一自己的 ID號數

TOP

回復 23# solely
不錯 你的觀念很正確,保護工作表只能防君子,不能防小人. 只有活頁簿設密碼,才能保密.

TOP

回復 42# peter460191
41# 附檔 VBA  ThisWorkbook   已告訴你密碼
  1. Private Sub Workbook_Open()
  2.     Worksheets("Secret").Visible = 2
  3.     If InputBox("請輸入密碼或取消") = "123" Then
  4.         MsgBox "USER,你好!!"
  5.         'Worksheets("Secret").Visible = -1
  6.         Worksheets("Secret").Visible = xlSheetVisible
  7.         Sheets("Secret").Cells.Font.ColorIndex = 56
  8.     Else
  9.         'MsgBox "你好!!"
  10.         Sheets("Secret").Cells.Font.ColorIndex = 2
  11.         Worksheets("Secret").Visible = 2
  12.     End If
  13. End Sub
複製代碼

TOP

        靜思自在 : 站在半路,比走到目標更辛苦。
返回列表 上一主題