+ Reply to Thread
Results 1 to 12 of 12

Close second workbook

  1. #1
    Registered User
    Join Date
    01-17-2013
    Location
    Harrison, MI
    MS-Off Ver
    Excel 2000
    Posts
    13

    Close second workbook

    I have a Workbook in Dropbox that can be shared with several users. In an attempt to stop a user from opening the workbook while it is opened by another user, I do the following.
    [I am SORRY but I do not know where the Code Tag is. I know that I need to put my code within this tag but ...]

    in ThisBorkBook Workbook_Open:

    I look for a specific file "LOCK_FILE"

    If "LOCK_FILE" does not exist, I ask the User for their name and then create "LOCK_FILE" with the current user's name as the first and only line in the text file.
    The Excel app then goes about its business with the user running various options from the "Welcome/Menu Page".
    When the user selects Exit from the "Welcome/Menu Page", I delete "LOCK_FILE" and Save and Quit the Excel app.

    If "LOCK_FILE" does exist, I display a message indicating who is using the file from the info in "LOCK_FILE".
    I then attempt to Close the Excel "instance" just opened. NOTE: This is the issue.
    The second user can then try to "sign in" at some other time.
    If the same user has the file for a long period, they can be notified and hopefully will close the Excel app.

    To this point, I have not been successful in closing this second "instance" of the Excel app.
    I have tried various things that work in Debug mode but will not do the job in "real time".
    My last attempt brings up a blank workbook after the close.

    I would add the code here but it is a mess because of so many attempts to solve my issue.
    Also if someone could explain how to use the Code Tag, I will supply what code I have, mess or not.


    I am sure there are other ways to accomplish what I am attempting to do.
    I do like having the ability to know who has the file open so that the second user can contact them to see when they might be finished or if they just forgot to Exit the app.
    I plan to have additional information in the lock file such as start time, user email address, user phone number, and other various pieces of information.

    Final comment. I am testing using just one computer. In real life, the users will be on their computers.
    I do have two computers and do not believe that this makes any difference in execution but I have not "wrestled it to the ground" yet.

    Thanks for any help you might provide.

    Dan

  2. #2
    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
    44,849

    Re: Close second workbook

    Fast answers need visual help. Please read the yellow banner at the top of this page on how to attach a file and a mocked up solution.
    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


  3. #3
    Registered User
    Join Date
    01-17-2013
    Location
    Harrison, MI
    MS-Off Ver
    Excel 2000
    Posts
    13

    Re: Close second workbook

    I believe that I have followed the instructions.

    Hopefully, a text file containing my code for the "ThisWorkBook Open" routine is attached.

    I went back and checked and I did not get it the first time. I believe it is there now!

    Thanks for your help.

    Dan
    Attached Files Attached Files

  4. #4
    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
    44,849

    Re: Close second workbook

    It has worked. However, it would be better if you uploaded a workbook with the "working" code in it. The content and structure is unimportant. It looks as though there are subroutines missing so I can't attempt to test this.

    Why do you have this: Sub xxx_Workbook_beforeClose(cancel As Boolean) ???

  5. #5
    Registered User
    Join Date
    01-17-2013
    Location
    Harrison, MI
    MS-Off Ver
    Excel 2000
    Posts
    13

    Re: Close second workbook

    OK, I have attached the app as it stands right now.
    It is a work in progress.

    Thank you for staying with me on this.

    Dan
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    01-17-2013
    Location
    Harrison, MI
    MS-Off Ver
    Excel 2000
    Posts
    13

    Re: Close second workbook

    I missed your question about the Sub xxx_Workbook_beforeClose(cancel as Boolean). This is an attempt to capture someone selecting the "X" to exit rather than using the supplied Menu Option. I don't know if the xxx's are to indicate that it is for an "X" exit or if I put them there so the subroutine would not execute. It seems as though I tested that yesterday and was taken here when I closed the app with the "X". (I had but a Stop statement in the code or did a break on the keyboard to get into the VBA code.

  7. #7
    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
    44,849

    Re: Close second workbook

    Putting the xxx_ in front of the event handler name means the event will not be trapped/executed.

  8. #8
    Registered User
    Join Date
    01-17-2013
    Location
    Harrison, MI
    MS-Off Ver
    Excel 2000
    Posts
    13

    Re: Close second workbook

    Thanks for letting me know what it is I am doing. I think I will remove the xxx and test it again.

    The original problem, however, is attempting to close a second occurrence of an Excell workbook.

  9. #9
    Registered User
    Join Date
    01-17-2013
    Location
    Harrison, MI
    MS-Off Ver
    Excel 2000
    Posts
    13

    Re: Close second workbook

    I have resolved my issue in a less-than-glamorous way. When I close, I have an empty Excel session. Before issuing the close command, I put out a message asking the use to close the window using the "X". This works every time but as I say it is not yet the "final answer". Any other thoughts?

  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
    44,849

    Re: Close second workbook

    I've had a quick look at your workbook this evening. I have not done a lot of testing so far, but enough to establish that, if I open the workbook on one machine, and then try to open it on a second machine, I get a message to say it's busy. So far, so good.

    This response is, of course, dependent on the user enabling macros when they open the workbook

    I note that, at this point, you are not using the content of the Lock File.

    I would urge you not to use Application.Quit in the Open or Close event handlers . . . unless you check that no other workbooks are open. Application.Quit does what it says on the tin. It quits (exits/closes) the application.

    Imagine, if a user is busy working on another spreadsheet, or maybe two or three. Then s/he decides to open this shared file. It's busy so it displays a message and shuts down Excel. If the user is lucky, s/he will be prompted to save her/his work and will heed that prompt. If shhe doesn't notice, or responds incorrectly, s/he could lose everything s/he has been working on.

  11. #11
    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
    44,849

    Re: Close second workbook

    Quote Originally Posted by DannyDont View Post
    I have resolved my issue in a less-than-glamorous way. When I close, I have an empty Excel session. Before issuing the close command, I put out a message asking the use to close the window using the "X". This works every time but as I say it is not yet the "final answer". Any other thoughts?
    Please upload the workbook in its current state.

  12. #12
    Registered User
    Join Date
    01-17-2013
    Location
    Harrison, MI
    MS-Off Ver
    Excel 2000
    Posts
    13

    Re: Close second workbook

    Thank you for the reply. I did wonder about Quit rather than Close. I have uploaded the current version.
    Dan
    Attached Files Attached Files

+ 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. [SOLVED] Copy 2 tabs from Workbook A to new workbook then close Workbook A without saving
    By ellenlewis in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-21-2023, 02:55 PM
  2. Copy from first workbook, close open new workbook paste close
    By johncarr1952 in forum Hello..Introduce yourself
    Replies: 2
    Last Post: 08-04-2021, 08:50 AM
  3. [SOLVED] Issue with Open, copy, close Macro - when trying to close workbook Clipboard error
    By seanpcorbett1 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-13-2016, 05:14 PM
  4. [SOLVED] Auto Close Msg Box after Time Period & Close Workbook
    By GJF36 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-24-2015, 10:25 AM
  5. [SOLVED] Close Userform2 on workbook close
    By zplugger in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-12-2015, 10:24 AM
  6. [SOLVED] Code to cut cell from one workbook, close same workbook, and paste in different workbook
    By kosherboy in forum Excel Programming / VBA / Macros
    Replies: 30
    Last Post: 03-13-2014, 04:01 PM
  7. Disable close workbook but still force users to close thru command button
    By rathig in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-18-2013, 07:29 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