Error Checking in Excel
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 4 of 4

Thread: Before Close Problem - Simple

  1. #1
    New Member
    Join Date
    Jan 2002
    Posts
    9
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    I am doing something wrong. I want to clear two forms and then save the workbook upon the user attempting to close the workbook.
    I keep getting an error message:Event Procedure declaration doesn't match description of event having the same name. What am I doing wrong?

    Private Sub Workbook_BeforeClose()

    'This macro clears the supplemental form
    Application.ScreenUpdating = False
    Sheets("supplemental").Select
    Range("h4").Select
    ActiveCell.Clear
    Range("C14").Select
    ActiveCell.FormulaR1C1 = ""
    Range("C16").Select
    ActiveCell.FormulaR1C1 = ""
    Application.ScreenUpdating = True

    'This macro clears the worksheet form
    Sheets("worksheet").Select
    Range("I4").Select
    ActiveCell.FormulaR1C1 = ""
    Range("E7").Select
    ActiveCell.FormulaR1C1 = ""
    Range("E8").Select
    ActiveCell.FormulaR1C1 = ""
    Range("E9").Select
    ActiveCell.FormulaR1C1 = ""
    Range("f7").Select
    ActiveCell.Clear
    Range("e12").Select
    ActiveCell.Clear
    Range("e15").Select
    ActiveCell.Clear
    Range("F19").Select
    ActiveCell.FormulaR1C1 = ""
    Range("G19").Select
    ActiveCell.FormulaR1C1 = ""
    Range("H19").Select
    ActiveCell.FormulaR1C1 = ""
    Range("F21").Select
    ActiveCell.FormulaR1C1 = ""
    Range("F23").Select
    ActiveCell.FormulaR1C1 = ""
    Range("H23:I23").Select
    ActiveCell.FormulaR1C1 = ""
    Range("F25").Select
    ActiveCell.FormulaR1C1 = ""
    Range("F27").Select
    ActiveCell.FormulaR1C1 = ""
    Range("F29").Select
    ActiveCell.FormulaR1C1 = ""
    Range("e31").Select
    ActiveCell.Clear
    Range("e32").Select
    ActiveCell.Clear
    Range("E34:F34").Select
    ActiveCell.FormulaR1C1 = ""
    Range("E36:F36").Select
    ActiveCell.FormulaR1C1 = ""
    Range("E38").Select
    ActiveCell.Clear

    ActiveWorkbook.save
    End Sub

  2. #2
    New Member
    Join Date
    Apr 2002
    Location
    Lawrence, KS
    Posts
    29
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Workbook_BeforeClose(Cancel As Boolean)

    see your problem now?
    you must include "Cancel As Boolean" as an argument, but you don't have to do anything with it.

  3. #3
    New Member
    Join Date
    Jan 2002
    Posts
    9
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    I surfed around to find what I needed and ignored the boolean comment because I didn't know what it meant.

    Figures it was too simple. Thanks!!

  4. #4
    MrExcel MVP Mark O'Brien's Avatar
    Join Date
    Feb 2002
    Location
    Columbus, OH, USA
    Posts
    3,530
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Quick tip as well.

    When you are in the worksheet or the workbook object you can access the events pretty easily (or userforms for that matter). There are two combo boxes at the top of the VBE when you are in these modules. The one on the left lets you select any object that is part of the object, the combobox on the right lets you choose an event. (this will help you to avoid missing out arguments in the future)

    HTH.

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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