Consulting

Results 1 to 17 of 17

Thread: save and close an excel sheet when I press the Windows + L buttons

  1. #1
    VBAX Regular
    Joined
    May 2016
    Posts
    8
    Location

    Question save and close an excel sheet when I press the Windows + L buttons

    Good afternoon,

    I want to save and close an excel sheet when I press the Windows + L buttons
    The sheet can not be shared and so it has to be closed by the last user in order to be updated by other users, it turns out that if a user forgets to close, all the work of other users of the sheet is compromised, it can not access the same.

    Thank you in advance for your time.

    Regards

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Windows Key+L is to log off Windows.

    When you log off from Windows, Excel is closed. If it is not saved, the User is prompted to save.

    Please explain the situation you are having.

    See Also: http://www.vbaexpress.com/kb/getarticle.php?kb_id=515
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,729
    Location
    Windows Key+L is to log off Windows.

    Splitting a hair here, but Win+L is to lock your PC or switch accounts, not quite the same as logging off
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  4. #4
    VBAX Regular
    Joined
    May 2016
    Posts
    8
    Location
    Windows Key+L is not to log off Windows is to looking off the pc.

  5. #5
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Us old XP'ers ain't got no "Lock Computer." We only log off.

    In any case, the Windows Key turns control over to the Start Menu API. Any running Applications are out of the picture at that point.

    See if any of these help:

    http://www.howtogeek.com/howto/windo...ity-windows-l/

    https://www.tekrevue.com/tip/windows...-menu-toolbar/

    http://www.computerworld.com/article...and-hacks.html

    http://www.bleepingcomputer.com/tuto...-in-windows-8/

    http://www.itworld.com/article/29886...windows-8.html
    Last edited by SamT; 05-10-2016 at 02:52 PM.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  6. #6
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,064
    Location
    Quote Originally Posted by SamT View Post
    Us old XP'ers ain't got no "Lock Computer." We only log off.
    How about you upgrade young fella before you "log off" this tiny world we live on?
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  7. #7

  8. #8
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    I am thinking about it, Ted. If only so I can keep posting here.

    Zavra says, "Hey." She came to visit me last month.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  9. #9
    VBAX Regular
    Joined
    May 2016
    Posts
    8
    Location
    let me ask you something, it is possible to save and close an Excel sheet by pressing two keys?
    for example by pressing b + g

  10. #10
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Record a Macro. The Wizard will have a space to select Hotkeys. It doesn't matter what you Record, (just select a cell and type something.)

    Edit that Macro by replace any code in it with
    Me.Save
    Me.Close
    You might want to save and close the book at other times and Events. You can Use a "Universal" Save and Close Sub and call it from that Macro.

    Macro Code
    Sub MacroName
    'Some Macro comments
    
    SaveAndClose
    End Sub
    Put the following in the same Code Module that the Macro gets saved in
    Public Sub SaveAndClose()
    Me.Save
    Me.Close
    End Sub
    Public Sub CloseOnTime()
    Static CloseTime As Date
    
    'Cancel the previous close on time
    If Not CloseTime = 0 Then _
    Application.OnTime CloseTime, SaveAndClose, , False
    
    CloseTime = DateAdd("s", 300, Now) 'The Workbook will close in 300 seconds
    Application.OnTime CloseTime, SaveAndClose, , True
    
    End Sub
    Put the following Subs in the ThisWorkbook Module
    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Me.Save
    End Sub
    
    Private Sub Workbook_Open()
    CloseOnTime
    End Sub
    
    Private Sub Workbook_SheetActivate(ByVal Sh As Object)
    CloseOnTime
    End Sub
    
    Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    CloseOnTime
    End Sub
    
    Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
    CloseOnTime
    End Sub
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  11. #11
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,064
    Location
    Pieiro, if you feel the need to crosspost this thread, at least have the courage to indicate this to those members who are trying to assist.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  12. #12
    VBAX Regular
    Joined
    May 2016
    Posts
    8
    Location
    Good afternoon,
    I am very inexperienced in these things and do not know how to do what you ask me, can you tell me exactly what to do step by step so I can do what you ask?
    Maybe with an example I can understand what to do.
    Thank you

  13. #13
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    What is multiposting?

    Multiposting is the act of posting a single question to different forums around the same time.

    We discourage multiposting because it is like calling five cab companies and going with the one that comes first -- it shows disrespect for the volunteers that monitor this forum because they will unknowingly be helping someone who may have already received help elsewhere. Their time is no less important than that of the person asking the question.

    Many of the volunteers here visit multiple forums and can easily spot duplicate posts. Some of them may even reply to your posts with a link to your post on another forum. Don't be the person that gets caught.

    If you must post your question on a different forum, include a link to the question you have already posted on the previous forum(s). That way, those helping you can decide for themselves if you are already receiving the help you need somewhere else.

    If you are still confused, read A message to forum cross posters.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  14. #14
    VBAX Regular
    Joined
    May 2016
    Posts
    8
    Location
    Actually I put the initial issue in other forums, but I am just follow this, since I have not had any contact from the other forums.
    You can be sure that as soon as I have a solution to this question whether this or any other forum (unlikely since I have no answers) will be informed and the post will be closed as resolved.

  15. #15
    VBAX Regular
    Joined
    May 2016
    Posts
    8
    Location
    Record a Macro. The Wizard will have a space to select Hotkeys. It doesn't matter what you Record, (just select a cell and type something.)

    Edit that Macro by replace any code in it withMe.Save
    Me.Close

    Formatting tags added by mark007

    You might want to save and close the book at other times and Events. You can Use a "Universal" Save and Close Sub and call it from that Macro.

    Macro Code Sub MacroName 
          'Some Macro comments
         
        SaveAndClose 
    End Sub

    Formatting tags added by mark007

    Put the following in the same Code Module that the Macro gets saved in
    Public Sub SaveAndClose() 
        Me.Save 
        Me.Close 
    End Sub 
    
    Public Sub CloseOnTime() 
        Static CloseTime As Date 
         
          'Cancel the previous close on time
        If Not CloseTime = 0 Then _ 
        Application.OnTime CloseTime, SaveAndClose, , False 
         
        CloseTime = DateAdd("s", 300, Now)'The Workbook will close in 300 seconds
        Application.OnTime CloseTime, SaveAndClose, , True 
         
    End Sub 
    
    
    Put the following Subs in the ThisWorkbook Module
    Private Sub Workbook_BeforeClose(Cancel As Boolean) 
        Me.Save 
    End Sub 
     
    Private Sub Workbook_Open() 
        CloseOnTime 
    End Sub 
     
    Private Sub Workbook_SheetActivate(ByVal Sh As Object) 
        CloseOnTime 
    End Sub 
     
    Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range) 
        CloseOnTime 
    End Sub 
     
    Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range) 
        CloseOnTime 
    End Sub





    I am very inexperienced in these things and do not know how to do what you ask me, can you tell me exactly what to do step by step so I can do what you ask?

    Maybe with an example I can understand what to do.
    Thank you

  16. #16
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    that is very basic VBA. Perhaps you should hire someone to work more closely with you.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  17. #17
    VBAX Regular
    Joined
    May 2016
    Posts
    8
    Location
    all I have to do is copy and paste this code in VBA excel sheet in developer mode ????

Posting Permissions

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