Results 1 to 2 of 2

Thread: Save and Close workbook at a certain time
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    New Member
    Join Date
    May 2019
    Posts
    20
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Save and Close workbook at a certain time

    Hi Mr. Excel Friends,

    I want to have my workbook save and close certain times in the day. I have tried inputting this code in the "This Workbook" object:

    Code:
    Sub Close_Workbook()
    
    
        Dim Wkb As Workbook
        If Time() = Time.Value("13:30:00") Then
            ThisWorkbook.Close SaveChanges:=True
        End If
        
    End Sub
    But it isn't working. Can you help me?

    Thanks,

  2. #2
    Board Regular Logit's Avatar
    Join Date
    Aug 2016
    Location
    United States
    Posts
    2,802
    Post Thanks / Like
    Mentioned
    36 Post(s)
    Tagged
    1 Thread(s)

    Default Re: Save and Close workbook at a certain time

    .
    Here is one method :

    Paste this macro in the ThisWorkbook module :

    Code:
    Option Explicit
    
    
    Private Sub Workbook_Open()
        Call ScheduleClose
    End Sub

    Paste this in a Regular module :

    Code:
    
    
    
    Sub ScheduleClose()
        Application.OnTime Now + TimeSerial(13, 30, 0), "Kamikaze"
    End Sub
    
    
    Sub Kamikaze()
       
        Application.DisplayAlerts = False
        ThisWorkbook.Saved = True
        Application.Quit
        
    End Sub

Some videos you may like

User Tag List

Tags for this Thread

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
  •