+ Reply to Thread
Results 1 to 2 of 2

Not able to execute macro for Backup

  1. #1
    Registered User
    Join Date
    01-28-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    9

    Not able to execute macro for Backup

    Hi,
    I am trying to write macro for backup of excel sheet, but while executing the macro its giving the error.

    "Sub Macro1()
    '
    ' Macro1 Macro
    '
    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Dim Msg As String
    Dim ans As Integer
    Dim fname As String
    Dim MyDate
    Dim MyMonth
    MyDate = Date
    MyMonth = Month(MyDate)
    Msg = "Would you like to back up file?"
    ans = MsgBox(Msg, vbYesNo)
    If ans = vbYes Then
    ThisWorkbook.SaveAs Filename:="D:\Backup\" & MonthName(MyMonth) & "-" & Day(Date) & "-" & Year(Date) & "-" & ThisWorkbook.Name
    End If

    '
    End Sub"
    Last edited by Santoshmoni; 02-01-2011 at 12:55 AM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Not able to execute macro for Backup

    1) Hi Santoshmoni... Welcome to the forum.

    Be sure to read through the Forum Rules so you can use and follow them effectively. For instance, you'll need to EDIT that post above and put code tags around that code you used. (Like shown in my signature)

    2) I can offer some more specific suggestions more efficient/reliable code after you fix the post above, or you can search on your own about using the .SaveCopyAs method.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

+ 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