+ Reply to Thread
Results 1 to 12 of 12

Workbook BeforeSave Event causing workbook to close

Hybrid View

Jo2710 Workbook BeforeSave Event... 09-17-2014, 06:20 PM
Leith Ross Re: Workbook BeforeSave Event... 09-17-2014, 06:31 PM
TMS Re: Workbook BeforeSave Event... 09-17-2014, 06:33 PM
Leith Ross Re: Workbook BeforeSave Event... 09-17-2014, 06:38 PM
TMS Re: Workbook BeforeSave Event... 09-17-2014, 06:45 PM
Leith Ross Re: Workbook BeforeSave Event... 09-17-2014, 07:08 PM
Leith Ross Re: Workbook BeforeSave Event... 09-17-2014, 06:51 PM
TMS Re: Workbook BeforeSave Event... 09-17-2014, 07:01 PM
Leith Ross Re: Workbook BeforeSave Event... 09-17-2014, 07:26 PM
TMS Re: Workbook BeforeSave Event... 09-17-2014, 07:21 PM
Jo2710 Re: Workbook BeforeSave Event... 09-17-2014, 10:35 PM
Leith Ross Re: Workbook BeforeSave Event... 09-18-2014, 12:33 AM
  1. #1
    Registered User
    Join Date
    06-26-2014
    Location
    Christchurch, New Zealand
    MS-Off Ver
    2010
    Posts
    43

    Talking Workbook BeforeSave Event causing workbook to close

    Hi

    I'm trying to create a workbook which users update then send via a separate command button to the 'data collector'. I'm trying to build in that they can't save the workbook, only the 'data collector' can.
    I've added in the below event but when the user clicks OK on the message box the workbook closes, what I'd like it to do is when OK is clicked the user returns back to the workbook so they can 'click the send button'.

    Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    If Environ("Username") <> "jrussell" Then
     Cancel = True
     MsgBox "You cannot save this form, click the Send button instead"
    End If
    End Sub
    Can anyone see where I'm going wrong?

    Thanks!
    Last edited by Jo2710; 09-17-2014 at 10:35 PM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Workbook BeforeSave Event causing workbook to close

    Hello Jo2710,

    This where the Cancel argument comes in. Setting Cancel to True exits the event. Do this after the message is displayed.
    Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    If Environ("Username") <> "jrussell" Then
     MsgBox "You cannot save this form, click the Send button instead"
     Cancel = True
    End If
    End Sub
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,110

    Re: Workbook BeforeSave Event causing workbook to close

    @Leith: so you need
    Cancel = True
    twice?
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Workbook BeforeSave Event causing workbook to close

    @ Trevor,

    The site is a little slow in updating. Cancel is set only once, after the message is displayed.

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,110

    Re: Workbook BeforeSave Event causing workbook to close

    @Leith: ah, so it is, no surprise there ... and now it makes sense.

    So, basically, do whatever you want/need to do and THEN cancel.

    Cheers, TMS

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Workbook BeforeSave Event causing workbook to close

    @Trevor,

    No, it is Scottish Gaelic.

  7. #7
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Workbook BeforeSave Event causing workbook to close

    @ Trevor,

    Mar bu choir. (Exactly)

  8. #8
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,110

    Re: Workbook BeforeSave Event causing workbook to close

    In Klingon?

  9. #9
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Workbook BeforeSave Event causing workbook to close

    @ Trevor,

    I have notified Google many times that Irish (Gaeilge) and Scottish (Gàidhlig) are not the same language. But, they don't care.

  10. #10
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,110

    Re: Workbook BeforeSave Event causing workbook to close

    Ah, that's may be why Google tried (and failed) with Irish

  11. #11
    Registered User
    Join Date
    06-26-2014
    Location
    Christchurch, New Zealand
    MS-Off Ver
    2010
    Posts
    43

    Re: Workbook BeforeSave Event causing workbook to close

    Thanks so much Leith! Knew I was missing something logical!

  12. #12
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Workbook BeforeSave Event causing workbook to close

    Hello Jo2710,

    It is usually the simple things that escape our attention. I've done the same thing many times.

    I'll marked this post as solved.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Problem with Save & Close macro and beforeSave event
    By Danny_ in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-18-2013, 04:32 PM
  2. Workbook before close event
    By solnajeff in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-16-2007, 08:51 AM
  3. Workbook close event
    By kpriyac in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-18-2006, 02:25 PM
  4. [SOLVED] Excel WorkBook Close Event
    By Xcelion in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-27-2006, 11:35 AM

Tags for this Thread

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