Consulting

Results 1 to 3 of 3

Thread: Solved: encounter error

  1. #1

    Solved: encounter error

    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?

  2. #2
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    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:
    [vba]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[/vba]

    HTH,
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  3. #3
    dear ken,
    many thanks for your guidance

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •