| 
    
     |  | >Blue さん 
 ありがとうございました。
 API関数は使わなければいけないようなんで、もう少し勉強してみます。
 
 重ねて質問を失礼します。
 現在ユーザーフォーム2つを行き来するようになっているのですが、メニューフォームの
 選択と、メインフォームの戻るボタンの行き来では問題ないのですが、×ボタンでは
 メニューフォームは表示されますが、メインフォームは消えず、メニューからメインに
 戻るとエラーになってしまいます。
 ×ボタンに関する記述が間違っているのでしょうか?
 
 ■メニューフォーム
 
 Private Sub CommandButton1_Click()
 On Error GoTo error1
 Select Case OptionButton1.Value
 Case True
 SFg = 1
 Ans = MsgBox("作業1でよろしいですか?", vbYesNo, "作業選択")
 If Ans = vbYes Then
 Unload Me
 UserForm4.Show
 Me.Hide
 Else
 End If
 Case False
 SFg = 2
 Ans = MsgBox("作業2でよろしいですか?", vbYesNo, "作業選択")
 If Ans = vbYes Then
 Unload Me
 UserForm4.Show
 Me.Hide
 Else
 End If
 End Select
 Exit Sub
 error1: MsgBox "エラー"
 End Sub
 
 Private Sub CommandButton2_Click()
 On Error GoTo error1
 Ans = MsgBox("終了してよろしいですか?", vbYesNo, "作業選択")
 If Ans = vbYes Then
 ThisWorkbook.Close
 Else
 End If
 Exit Sub
 error1: MsgBox "エラー"
 End Sub
 Private Sub UserForm_Activate()
 
 If (SFg = 1) Or (SFg = 2) Then
 Select Case SFg
 Case 1
 Me.OptionButton1.Value = True
 Case Else
 Me.OptionButton2.Value = True
 End Select
 Else
 SFg = 1
 Me.OptionButton1.Value = True
 End If
 End Sub
 
 
 ■メインフォーム(戻るボタン)
 
 Private Sub CommandButton8_Click()
 Dim Ans As String
 Ans = MsgBox("メニュー画面に戻りますか?", vbYesNo, "選択")
 'Yesならメイン画面が開く
 If Ans = vbYes Then
 Unload Me
 Load UserForm2
 UserForm2.Show
 Else
 End If
 End Sub
 
 ■メインフォーム(右上×ボタン)
 
 Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
 
 If CloseMode <> vbFormCode Then
 Dim Ans As String
 Ans = MsgBox("メニュー画面に戻りますか?", vbYesNo, "選択")
 If Ans = vbYes Then
 Unload Me
 Load UserForm2
 UserForm2.Show
 Else
 End If
 Cancel = 1
 End If
 End Sub
 
 |  |