|
マクロを有効にしたときだけブックを非表示にしてUserForm1を表示させたいのですが次の記述では最後のUserForm1.Showのところで止まってしまいます。
Private Const fPASSWORD As String = "Passeord" & vbBack
Private Sub HideWindow()
Dim i As Long
For i = Windows.Count To 2 Step -1
Windows(i).Close
Next
Windows(1).Visible = False
Protect fPASSWORD, False, True
End Sub
Private Sub ShowWindow()
Unprotect fPASSWORD
Windows(1).Visible = True
Saved = True
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
If Saved Then Exit Sub
Select Case MsgBox("'" & Name & "' への変更を保存しますか?", vbExclamation Or vbYesNoCancel)
Case vbYes
HideWindow
Application.EnableEvents = False
Save
Application.EnableEvents = True
Case vbNo
Saved = True
Case vbCancel
Cancel = True
End Select
End Sub
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
HideWindow
Application.EnableEvents = False
Save
Application.EnableEvents = True
ShowWindow
Cancel = True
End Sub
Private Sub Workbook_Open()
' ブックを非アクティブにする。
Application.Visible = False
UserForm1.Show
End Sub
|
|