By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,197 Members | 1,173 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,197 IT Pros & Developers. It's quick & easy.

Setting macro to save as current date

P: 2
Not sure if this is the place to find the answer to my need, so hopefully someone can help. I have created a micro enabled Word template and my wish is to have a command button on the document perform a save as and to close the template without changing the original file. My issue is that I want the button to save the document as the current date, but have not figured out how to string it. I am working in the VBA format of Microsoft 2007. Here is what I have so far, with {{{Current Date}}} being the current date when saved


Private Sub CommandButton1_Click()
' Saveandexit Macro
ChangeFileOpenDirectory " Y:\Truck Check\Engine 1\"
ActiveDocument.ExportAsFixedFormat OutputFileName:= _
"K:\Truck Check\Engine 1\{{{Current Date}}}.pdf", ExportFormat:= _
wdExportFormatPDF, OpenAfterExport:=false, OptimizeFor:= _
wdExportOptimizeForPrint, Range:=wdExportAllDocument, From:=1, To:=1, _
Item:=wdExportDocumentContent, IncludeDocProps:=False, KeepIRM:=True, _
CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
BitmapMissingFonts:=True, UseISO19005_1:=False
' stopexit Macro
End Sub
Mar 21 '10 #1
Share this Question
Share on Google+
3 Replies

Expert 5K+
P: 8,638
Expand|Select|Wrap|Line Numbers
  1. ChangeFileOpenDirectory "Y:\Truck Check\Engine 1\"
  2. ActiveDocument.ExportAsFixedFormat OutputFileName:= _
  3. "Y:\Truck Check\Engine 1\" & Format(Date, "mmddyyyy") & ".pdf", ExportFormat:=wdExportFormatPDF, _
  4. OpenAfterExport:=False, OptimizeFor:=wdExportOptimizeForPrint, _
  5. Range:=wdExportAllDocument, From:=1, To:=1, Item:= _
  6. wdExportDocumentContent, IncludeDocProps:=False, KeepIRM:=True, CreateBookmarks:= _
  7. wdExportCreateNoBookmarks, DocStructureTags:=True, BitmapMissingFonts:= _
  8. True, UseISO19005_1:=False
Mar 21 '10 #2

P: 2
I had seen several post on other web sites, and had been trying to input the string to complete the date issue, but had no luck. Your string worked perfectly, just that it took me some time to understand the whole aspect of making it work, but was finally able to manipulate the problem I was having.

Thanks very much, and the guys at the fire dept Thank you as well.
Mar 21 '10 #3

Expert 5K+
P: 8,638
You are quite welcome.
Mar 22 '10 #4

Post your reply

Sign in to post your reply or Sign up for a free account.