+ Reply to Thread
Results 1 to 9 of 9

auto save when open and adding current date to file

Hybrid View

  1. #1
    Registered User
    Join Date
    07-30-2012
    Location
    Shippensburg, PA
    MS-Off Ver
    office 2007, Frontpage and Visio 2003
    Posts
    22

    Question auto save when open and adding current date to file

    I am trying to idiot proof my workbook to auto save upon opening with the same file name with the current date added on the end. I have the file write protected by selecting properties and checking the box to write protect.

    I do not see a new file name being created.

    Private Sub Workbook_Open()
        objWorkbook.SaveAs "K:\Test\" & objWorkbook.Name & Format(Date, "MMMddYYYY")
    End Sub
    Thanks in Advance,

    Christopher aka Ferrum
    Last edited by ferrum_equitis; 12-04-2012 at 01:04 PM.

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 365 on Win11 (365 on Win11 (desktop), 365 on Win11 (notebook)
    Posts
    8,207

    Re: auto save when open and adding current date to file

    Hi, Christopher,

    on opening objWorkbook should be empty. You should rely on ThisWorkbook instead
    Private Sub Workbook_Open()
        With ThisWorkbook
          .SaveCopyAs "K:\Test\" & Left(.Name, Len(.Name) - 5) & Format(Date, "MMMDDYYYY") & ".xlsm"
        End With
    End Sub
    I needed to add a folder which is a Trusted location as well.

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Registered User
    Join Date
    07-30-2012
    Location
    Shippensburg, PA
    MS-Off Ver
    office 2007, Frontpage and Visio 2003
    Posts
    22

    Question Re: auto save when open and adding current date to file

    Thanks for this, I tried it, but still no new file noted.
    My workbook is not empty.
    Will that matter?

    Christopher aka Ferrum
    Last edited by ferrum_equitis; 12-03-2012 at 03:03 AM.

  4. #4
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 365 on Win11 (365 on Win11 (desktop), 365 on Win11 (notebook)
    Posts
    8,207

    Re: auto save when open and adding current date to file

    Hi, Christopher,

    The commands will save a copy of the workbook, no matter if there is data in it or not. Difference between SaveAs and SaveCopyAs is that the last of the two leaves you in the original workbook (save the new workbook without changing activeworkbook) while the first gets you to the newly saved workbook.

    I tried the code prior to posting and had to djust the drive and folder to suit on my system (running Windows7 and 2007).

    Ciao,
    Holger

  5. #5
    Registered User
    Join Date
    07-30-2012
    Location
    Shippensburg, PA
    MS-Off Ver
    office 2007, Frontpage and Visio 2003
    Posts
    22

    Re: auto save when open and adding current date to file

    I closed everything and open up the file again, and nothing. No new file.... I am using 2007 and Win XP. I am including the file to be looked at. The code I placed at the very top.

    Thanks

    Christopher "Ferrum"
    Attached Files Attached Files

  6. #6
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 365 on Win11 (365 on Win11 (desktop), 365 on Win11 (notebook)
    Posts
    8,207

    Re: auto save when open and adding current date to file

    Hi, Christopher,

    the Workbook_Open-event will only get fired if placed in ThisWorkbook (currently itīs placed behind STATUSBOARD where it canīt get fired). Please relocate the code and try again.

    Ciao,
    Holger

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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