excel vba 隱藏 sheet?

2016-09-15 5:30 pm
請問要如何改下列程式碼
才能變成 一開啟excel時自動隱藏所有sheet
輸入正確得密碼之後 才會解除隱藏的sheet

程式碼如下


Private Sub Workbook_Open() '啟動程式
Dim x

x = InputBox("請輸入帳號密碼")
If x = "309" Then '設定密碼為 309
For i = 1 To Sheets.Count '由系統開啟工作表的隱藏



Sheets(i).Visible = True '取消工作表的隱藏
Next

Else
MsgBox "密碼錯誤", 0 + 16, "錯誤訊息"
Me.Close 0 '無法開啟時工作表繼續隱藏
Application.Quit
End If

End Sub

回答 (1)

2016-09-16 12:20 pm
✔ 最佳答案
Private Sub Workbook_Open()
Call 隱藏
End Sub

Sub 隱藏()
Dim x As String
For i = 2 To Sheets.Count
Sheets(i).Visible = False
Next
x = InputBox("輸入密碼", "輸入")
If x = "309" Then
For i = 2 To Sheets.Count
Sheets(i).Visible = True
Next
Else
Msg = MsgBox("密碼錯誤是否繼續", vbOKCancel, "輸入密碼")
If Msg = 1 Then
Call 隱藏
Else
Exit Sub
End If
End If
End Sub


收錄日期: 2021-05-03 13:46:40
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20160915093055AAm7jjS

檢視 Wayback Machine 備份