+ Reply to Thread
Results 1 to 2 of 2

Macro for saving file on Auto Date

  1. #1
    Prakash
    Guest

    Macro for saving file on Auto Date

    I want to know while writing a Macro how to automatically save a file which
    is open on current date. Say File xxx.xls as xxx_date.xls. This has to be
    done automatically. Help me in solving this.

    Thanks,
    --
    Prakash

  2. #2
    Forum Expert Simon Lloyd's Avatar
    Join Date
    03-02-2004
    Location
    locked in the cage
    MS-Off Ver
    All the ones my homepage shows
    Posts
    3,161

    Try this!

    This makes a dated back up read only copy of a file at the end of each month if it is opened at the end of the month taking in to account not being used at weekends please feel free to modify this code to suit your needs.

    Simon

    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Dim lDat_Today As Date
    Dim lDat_Tomorrow As Date
    Dim sStr As String
    Dim myattr

    With ThisWorkbook
    If ActiveWorkbook.ReadOnly Then Exit Sub
    lDat_Today = Date
    If Format(Date, "ddd") = "Fri" Then
    lDat_Tomorrow = Date + 3
    Else
    lDat_Tomorrow = Date + 1
    End If

    If Not Month(lDat_Today) = Month(lDat_Tomorrow) Then
    sStr = .Path & "\" & _
    Left(.Name, InStr(1, _
    LCase(.Name), _
    ".xls") - 1) & _
    " - " & Format(Now, "yyyymmdd") & ".xls"
    On Error Resume Next
    SaveCopyAs sStr
    On Error GoTo 0
    SetAttr sStr, vbReadOnly
    End If
    End With
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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