警告メッセージの非表示 |
|
|
---|---|---|
処理途中表示のOFF 処理途中表示のON |
|
Yes/Noを問う |
|
|
---|---|---|
処理途中表示のOFF メッセージを表示して、TIMEOUTで戻る |
|
|
プロンプトを出して、入力を得る |
|
Excelのセルを使って初期設定を行う |
|
|
---|---|---|
文字の読み上げ |
|
|
セル内容の読み上げ |
|
|
数字を2ケタづつに分けて読む |
|
|
C:\Sample.txtの内容を1行ずつ読み上げ |
|
|
ビープ音を鳴らす |
|
1 2 3 | Range( "A1" ). Select ActiveSheet.Paste Application.CutCopyMode = False |
1 2 3 4 5 6 7 8 9 | On Eerror GoTo ErrorHandler Exit Sub ErrorHandler: MsgBox "処理が完了しませんでした。" & vbCrLf & "問題を解決して、再度処理を実行してください。" _ , vbExclamation, "TEST2" End Sub |
MsgBoxのアイコン変更は第2引数
vbExclamation 「注意」の黄色アイコン
vbCritical 「停止」の赤いアイコン
vbInformation 「案内」アイコン
タイトルの変更は第3引数に文字列指定
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | Option Explicit '******************************************************************************* ' エラー表記を独自にコントロールする例② '******************************************************************************* Sub TEST3() Dim vrnINPUT As Variant Dim intNUM As Integer vrnINPUT = "a" ' 入力データ On Error GoTo ERR2 intNUM = vrnINPUT MsgBox "結果は" & intNUM & "で正常終了しました。" Exit Sub '------------------------------------------------------------------------------- ' エラー時の飛び先(行ラベル) ERR2: If MsgBox( "実行時エラー:" & Err.Number & " " & _ Err.Description & vbCr & _ "入力データは「" & vrnINPUT & "」です。ゼロに置き換えますか?" , _ vbExclamation + vbYesNo, "TEST3" ) = vbYes Then ' ゼロを上書き intNUM = 0 ' エラー発生箇所の次に進める Resume Next End If End Sub |
ErrorHandlerからの戻りは2種類
Resume :元の行に戻る
Resume Next :元の次の行に戻る
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | Sub Sample1() Dim RowCnt, ColCnt, StartRow, StartColumn As Integer Dim Max_Row, Max_Column As Integer Dim LoopArea As Range Dim SelectArea As String Dim I As Integer Dim J As Integer Dim K As Integer SelectArea = Selection.Address RowCnt = Selection.Row ColCnt = Selection.Column Set LoopArea = Selection StartRow = LoopArea.Cells(1).Row StartColumn = LoopArea.Cells(1).Column Max_Row = LoopArea.Cells(LoopArea.Count).Row Max_Column = LoopArea.Cells(LoopArea.Count).Column K = StartRow FinalEnd = False Do For I = 1 To 5 Application.Speech.Speak Cells(K, StartColumn).Value K = K + 1 If K > Max_Row Then FinalEnd = True Exit For End If Next I If FinalEnd = True Then Exit Do J = MsgBox( "続けますか?" , vbYesNo) Loop While J = vbYes End Sub |