Consulting

Results 1 to 3 of 3

Thread: Insert today's date, save file and close

  1. #1
    VBAX Newbie
    Joined
    Jun 2008
    Posts
    1
    Location

    Insert today's date, save file and close

    Hi,

    I need help to write a macro that, upon press of a button, the date in a specific cell updates to today's date and then the file is saved and closed.

    Thanks

  2. #2
    VBAX Mentor
    Joined
    Oct 2007
    Posts
    372
    Location
    Insert something like this into your button code:

    [VBA]sub addtime
    Range("A1").Select 'where A1 is your "specific cell"
    Selection=NOW()
    End sub[/VBA]

  3. #3
    VBAX Expert
    Joined
    Dec 2007
    Posts
    522
    Location
    Try the following code.

    You need to add the button, go to "Design Mode" on the VBA toolbar.

    Then right click the button and go to "View Code" and insert the routine below, without the sub, End Sub commands.

    [vba]
    Option Explicit

    Sub InsertDate_Close_and_Save_Activeworkbook()

    'The following Sheet reference will need to be changed to suit
    ActiveWorkbook.Sheets(1).Range("A1").Value = Format(Now, "d/mm/yyyy h:mm") '<= Change format of Time Stamp to suit

    ' This will close and save the Activeworkbook
    ActiveWorkbook.Close savechanges:=True

    End Sub
    [/vba]

    regards,

Posting Permissions

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