演習35 「API」 の解説 No.1
[x]ボタンを無効にして Beep音 を鳴らすだけなら、Win32 API を使わずに
Excel VBA の 'UserForm_QueryClose' イベント のみを用いて、次の
コードで可能である。
《閉じる[x]ボタンを 無効(Beep音) にする》
'------------- [ThisWorkbook] -------------
Private Sub Workbook_Open()
UserForm1.Show
End Sub
'-------------- [UserForm1] --------------
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
'[x]ボタン無効(Beep音)
If CloseMode <> vbFormCode Then
Beep '↑コードから Unload ステートメントを実行の意味
Cancel = 1 '←0以外を設定すると閉じない
End If
End Sub
'-----------------------------------------
Private Sub CommandButton1_Click()
Unload Me
End Sub
'-----------------------------------------
API No.2 へ移る. back top