excel vba ru



Excel vba обработка ошибок

Автор @ntykus задал вопрос в разделе Другие языки и технологии

VBA Excel Обработка ошибки и получил лучший ответ

Ответ от Makfromkz[гуру]
из справки VBA:On Error StatementEnables an error-handling routine and specifies the location of the routine within a <a target=\"_blank\" >procedure</a>; can also be used to disable an error-handling routine.SyntaxOn Error GoTo lineOn Error Resume NextOn Error GoTo 0The On Error statement syntax can have any of the following forms:StatementDescriptionOn Error GoTo lineEnables the error-handling routine that starts at line specified in the required line <a target=\"_blank\" >argument</a>. The line argument is any <a target=\"_blank\" >line label</a> or <a target=\"_blank\" >line number</a>. If a <a target=\"_blank\" >run-time error</a> occurs, control branches to line, making the error handler active. The specified line must be in the same procedure as the On Error statement; otherwise, a <a target=\"_blank\" >compile-time</a> error occurs.On Error Resume NextSpecifies that when a run-time error occurs, control goes to the <a target=\"_blank\" >statement</a> immediately following the statement where the error occurred where execution continues. Use this form rather than On Error GoTo when accessing objects.On Error GoTo 0Disables any enabled error handler in the current procedure.и там же пример:Sub InitializeMatrix(Var1, Var2, Var3, Var4) On Error GoTo ErrorHandler . . Exit SubErrorHandler: . . Resume NextEnd SubилиSub OnErrorStatementDemo() On Error GoTo ErrorHandler \' Enable error-handling routine. Open \"TESTFILE\" For Output As #1 \' Open file for output. Kill \"TESTFILE\" \' Attempt to delete open \' file. On Error Goto 0 \' Turn off error trapping. On Error Resume Next \' Defer error trapping. ObjectRef = GetObject(\"MyWord.Basic\") \' Try to start nonexistent \' object, then test for \'Check for likely Automation errors. If Err.Number = 440 Or Err.Number = 432 Then \' Tell user what happened. Then clear the Err object. Msg = \"There was an error attempting to open the Automation object!\" MsgBox Msg, , \"Deferred Error Test\" Err.Clear \' Clear Err object fields End If Exit Sub \' Exit to avoid handler.ErrorHandler: \' Error-handling routine. Select Case Err.Number \' Evaluate error number. Case 55 \' \"File already open\" error. Close #1 \' Close open file. Case Else \' Handle other situations here... End Select Resume \' Resume execution at same line \' that caused the error.End Sub

Ответ от IRQ[гуру]
используй обработчик on error

Ответ от 3 ответа[гуру]
Привет! Вот подборка тем с похожими вопросами и ответами на Ваш вопрос: VBA Excel Обработка ошибки
Visual Basic for Applications на Википедии
Посмотрите статью на википедии про Visual Basic for Applications
 

Ответить на вопрос:

Имя*

E-mail:*

Текст ответа:*
Проверочный код(введите 22):*