PDA

View Full Version : Solved: encounter error



benong
08-25-2010, 07:01 PM
hi,
I created a userform in workbook 1.
The input data from userform will be added to workbook 2.
I've added to the script:
Application.ScreenUpdating = False

Whenever i encounter problem executing the script, the workbook 2 will open and stay on screen which the user can see the data.
Maybe mess with it and worst of all, save & replace the original data!
Is there a method of not displaying the workbook 2, irregardless of what type of error i may encounter in the script?

Ken Puls
08-25-2010, 11:45 PM
I presume when you are talking about errors, you mean that you have an error which gives the user the option to debug/cancel the macro. And doing clicking either of those exposes Workbook2, correct?

The answer is to implement some error handling so that, if an error is encountered, you close workbook2 before returning control to the user.

Basic error handling looks like this:
Sub Test()

On Error GoTo ErrHandler

'Do what you normally want to do here

Exit Sub

ErrHandler:
MsgBox "Uh oh! I encountered an error. Please tell benong so it can be fixed!"
'Code to close the workbook here
End Sub

HTH,

benong
08-29-2010, 06:12 PM
dear ken,
many thanks for your guidance :)