One time macro, only on open of specific file name.

Hootywho

Board Regular
Joined
Oct 11, 2010
Messages
90
The title probably does not describe my issue.
I am using code on a "Master" file to automatically change the file name and add the current date on the end upon opening. Is there anyway to disable that macro automatically on the new file created?

The following is the code I call when master file opens...

Code:
Sub Save_File_As()
'   This macro is used to change the name of the file when initially opened to add the date at the end
'   and close the master file. 

    Dim file_name As Variant
    file_name = Application.GetSaveAsFilename(FileFilter:="Microsoft Excel file (*.xls), *.xls")
    If file_name <> False Then
      ActiveWorkbook.SaveAs "New File Name" & " " & Format(Date, "dddd mm-dd-yyyy")
  
    End If
    Sheets("Sheet Name").Select
    Range("c4").Select
    ActiveWorkbook.Save
    End Sub
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Put an IF statement to test if the current name is New File Name.xls where NewFile Name is the actual name of your Master fie. If it is not currently New File Name then exit the macro.

Code:
Sub Save_File_As()
'   This macro is used to change the name of the file when initially opened to add the date at the end
'   and close the master file.

    Dim file_name As Variant
    
    If ThisWorkbook.Name = "[COLOR="Red"]New File Name[/COLOR].xls" Then
    
      file_name = Application.GetSaveAsFilename(FileFilter:="Microsoft Excel file (*.xls), *.xls")
      If file_name <> False Then
        ActiveWorkbook.SaveAs "New File Name" & " " & Format(Date, "dddd mm-dd-yyyy")
    
      End If
      Sheets("Sheet Name").Select
      Range("c4").Select
      ActiveWorkbook.Save
    
    End If
    
End Sub

Change "New File Name" to your actual name of the Master workbook.
 
Upvote 0

Forum statistics

Threads
1,224,613
Messages
6,179,903
Members
452,948
Latest member
Dupuhini

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top