Datestamping a file created by a macro

  • Thread starter Thread starter michaelberrier
  • Start date Start date
M

michaelberrier

I have a great macro that puts a worksheet from an open workbook, does
some editing and saves with a specific file name.

And, I found this code here:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Sheets("yourworksheet").Range("desiredrange") = Now
End Sub

to change a cell value from NOW() to the date it was saved.

Now, the problem.

The above code belongs in the ThisWorkbook part of the book's code, and
I don't know where to put that in the macro that creates the workbook
to put it in that part of the new workbook.

Thanks to all.
 
I'm stupid. Here is the code that makes the worksheet. I guess I just
need to know where to put the code above into this so that it ends up
in the ThisWorkbook part.

..SaveAs Filename:="C:\Manifest\Manifest Archive\" &
Worksheets("MANIFEST").Range("C12").Value & " " &
Worksheets("MANIFEST").Range("C13").Value & " " &
Worksheets("MANIFEST").Range("G14").Value & " " &
Worksheets("MANIFEST").Range("D10").Value & " " & Format(Now,
"mm-dd-yyyy hh-mm-ss")
.Close savechanges:=False 'if you're done with it.
ActiveWorkbook.Saved = True
ActiveWorkbook.Close

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top