+ Reply to Thread
Results 1 to 10 of 10

Run macro on exit worksheet/workbook

  1. #1
    Ron de Bruin
    Guest

    Re: Run macro on exit worksheet/workbook

    Hi

    Better use the beforeclose event so the user can cancel the close

    Copy this in the thisworkbook module

    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Dim ans As Long
    ans = MsgBox("Do you fill in your working hours?", vbOKCancel)
    If ans = vbOK Then
    'do nothing
    ElseIf ans = vbCancel Then
    Cancel = True
    End If
    End Sub


    --
    Regards Ron de Bruin
    http://www.rondebruin.nl


    "toontje" <abreijer1@zonnet.nl> wrote in message news:36255$42efdbfb$3e3ba125$15720@news.versatel.nl...
    >I am looking for a macro that opens a msgbox when exit the workbook to remind you
    > like "you fill in your working hours?"
    >
    > is that Private Sub AutoClose() ?
    >
    > and where do i put it?




  2. #2
    Bob Phillips
    Guest

    Re: Run macro on exit worksheet/workbook

    You need Workbook_BeforeClose, as you can Cancel the close

    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    If your condition not met Then
    Cancel=True
    End If
    End Sub

    'This is workbook event code.
    'To input this code, right click on the Excel icon on the worksheet
    '(or next to the File menu if you maximise your workbooks),
    'select View Code from the menu, and paste the code

    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "toontje" <abreijer1@zonnet.nl> wrote in message
    news:36255$42efdbfb$3e3ba125$15720@news.versatel.nl...
    > I am looking for a macro that opens a msgbox when exit the workbook to
    > remind you
    > like "you fill in your working hours?"
    >
    > is that Private Sub AutoClose() ?
    >
    > and where do i put it?




  3. #3
    Bill Kuunders
    Guest

    Re: Run macro on exit worksheet/workbook

    You will need to put it in the workbook code.

    Right click on the small picture to the left of the menu item "File"
    select "workbook" in the dropdown next to "general"
    select "before close" or if you like "before save" in the dropdown next to
    "open"
    and enter
    Msgbox "Heb je je uren ingevuld????"
    between the lines already there.

    Have fun.

    --
    Groeten vanuit Nieuw Zeeland
    Willy Kuunders

    "toontje" <abreijer1@zonnet.nl> wrote in message
    news:36255$42efdbfb$3e3ba125$15720@news.versatel.nl...
    >I am looking for a macro that opens a msgbox when exit the workbook to
    >remind you
    > like "you fill in your working hours?"
    >
    > is that Private Sub AutoClose() ?
    >
    > and where do i put it?




  4. #4
    Ron de Bruin
    Guest

    Re: Run macro on exit worksheet/workbook

    Hi

    Better use the beforeclose event so the user can cancel the close

    Copy this in the thisworkbook module

    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Dim ans As Long
    ans = MsgBox("Do you fill in your working hours?", vbOKCancel)
    If ans = vbOK Then
    'do nothing
    ElseIf ans = vbCancel Then
    Cancel = True
    End If
    End Sub


    --
    Regards Ron de Bruin
    http://www.rondebruin.nl


    "toontje" <abreijer1@zonnet.nl> wrote in message news:36255$42efdbfb$3e3ba125$15720@news.versatel.nl...
    >I am looking for a macro that opens a msgbox when exit the workbook to remind you
    > like "you fill in your working hours?"
    >
    > is that Private Sub AutoClose() ?
    >
    > and where do i put it?




  5. #5
    Bob Phillips
    Guest

    Re: Run macro on exit worksheet/workbook

    You need Workbook_BeforeClose, as you can Cancel the close

    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    If your condition not met Then
    Cancel=True
    End If
    End Sub

    'This is workbook event code.
    'To input this code, right click on the Excel icon on the worksheet
    '(or next to the File menu if you maximise your workbooks),
    'select View Code from the menu, and paste the code

    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "toontje" <abreijer1@zonnet.nl> wrote in message
    news:36255$42efdbfb$3e3ba125$15720@news.versatel.nl...
    > I am looking for a macro that opens a msgbox when exit the workbook to
    > remind you
    > like "you fill in your working hours?"
    >
    > is that Private Sub AutoClose() ?
    >
    > and where do i put it?




  6. #6
    Bill Kuunders
    Guest

    Re: Run macro on exit worksheet/workbook

    You will need to put it in the workbook code.

    Right click on the small picture to the left of the menu item "File"
    select "workbook" in the dropdown next to "general"
    select "before close" or if you like "before save" in the dropdown next to
    "open"
    and enter
    Msgbox "Heb je je uren ingevuld????"
    between the lines already there.

    Have fun.

    --
    Groeten vanuit Nieuw Zeeland
    Willy Kuunders

    "toontje" <abreijer1@zonnet.nl> wrote in message
    news:36255$42efdbfb$3e3ba125$15720@news.versatel.nl...
    >I am looking for a macro that opens a msgbox when exit the workbook to
    >remind you
    > like "you fill in your working hours?"
    >
    > is that Private Sub AutoClose() ?
    >
    > and where do i put it?




  7. #7
    toontje
    Guest

    Run macro on exit worksheet/workbook

    I am looking for a macro that opens a msgbox when exit the workbook to
    remind you
    like "you fill in your working hours?"

    is that Private Sub AutoClose() ?

    and where do i put it?

  8. #8
    Ron de Bruin
    Guest

    Re: Run macro on exit worksheet/workbook

    Hi

    Better use the beforeclose event so the user can cancel the close

    Copy this in the thisworkbook module

    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Dim ans As Long
    ans = MsgBox("Do you fill in your working hours?", vbOKCancel)
    If ans = vbOK Then
    'do nothing
    ElseIf ans = vbCancel Then
    Cancel = True
    End If
    End Sub


    --
    Regards Ron de Bruin
    http://www.rondebruin.nl


    "toontje" <abreijer1@zonnet.nl> wrote in message news:36255$42efdbfb$3e3ba125$15720@news.versatel.nl...
    >I am looking for a macro that opens a msgbox when exit the workbook to remind you
    > like "you fill in your working hours?"
    >
    > is that Private Sub AutoClose() ?
    >
    > and where do i put it?




  9. #9
    Bob Phillips
    Guest

    Re: Run macro on exit worksheet/workbook

    You need Workbook_BeforeClose, as you can Cancel the close

    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    If your condition not met Then
    Cancel=True
    End If
    End Sub

    'This is workbook event code.
    'To input this code, right click on the Excel icon on the worksheet
    '(or next to the File menu if you maximise your workbooks),
    'select View Code from the menu, and paste the code

    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "toontje" <abreijer1@zonnet.nl> wrote in message
    news:36255$42efdbfb$3e3ba125$15720@news.versatel.nl...
    > I am looking for a macro that opens a msgbox when exit the workbook to
    > remind you
    > like "you fill in your working hours?"
    >
    > is that Private Sub AutoClose() ?
    >
    > and where do i put it?




  10. #10
    Bill Kuunders
    Guest

    Re: Run macro on exit worksheet/workbook

    You will need to put it in the workbook code.

    Right click on the small picture to the left of the menu item "File"
    select "workbook" in the dropdown next to "general"
    select "before close" or if you like "before save" in the dropdown next to
    "open"
    and enter
    Msgbox "Heb je je uren ingevuld????"
    between the lines already there.

    Have fun.

    --
    Groeten vanuit Nieuw Zeeland
    Willy Kuunders

    "toontje" <abreijer1@zonnet.nl> wrote in message
    news:36255$42efdbfb$3e3ba125$15720@news.versatel.nl...
    >I am looking for a macro that opens a msgbox when exit the workbook to
    >remind you
    > like "you fill in your working hours?"
    >
    > is that Private Sub AutoClose() ?
    >
    > and where do i put it?




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1