{"id":3458,"date":"2021-07-07T14:22:17","date_gmt":"2021-07-07T21:22:17","guid":{"rendered":"https:\/\/SUMMALAI.COM\/?p=3458"},"modified":"2021-07-07T14:22:18","modified_gmt":"2021-07-07T21:22:18","slug":"how-to-add-month-year-to-filename-in-vba","status":"publish","type":"post","link":"https:\/\/SUMMALAI.COM\/?p=3458","title":{"rendered":"How to add month\/year to filename in VBA"},"content":{"rendered":"\n<p>I got a question like this:<\/p>\n\n\n\n<p>Is it possible when saving a file in vba to add the current month\/year to the end of the filename with the format mmm\/yy?<\/p>\n\n\n\n<p>The code I have so far&#8230;..<\/p>\n\n\n\n<p>&lt;code&gt;Workbooks(&#8220;test.xls&#8221;).SaveCopyAs (&#8220;C:\\xls files\\test.xls&#8221;)&lt;\/code&gt;<\/p>\n\n\n\n<p>I need the month\/year to be added to test.xls so that it looks like &#8220;test_Oct-07.xls&#8221;<\/p>\n\n\n\n<p>Let&#8217;s do the magic with below codes<\/p>\n\n\n\n<p><br><strong>Workbooks(&#8220;test.xls&#8221;).SaveCopyAs (&#8220;C:\\xls files\\test_&#8221; &amp; Format(Date,&#8221;mmm-yy&#8221;) &amp; &#8220;.xls&#8221;)<\/strong><\/p>\n\n\n\n<p>Below, it is another sample for adding year and last month in different format:<\/p>\n\n\n\n<p> <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Path = ActiveWorkbook.Path &amp; \"\\\"\nnfname = \"SLGA_NCD_\" &amp; Format(Now() - 30, \"yyyy-mmm\") &amp; \".xlsx\"<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img fetchpriority=\"high\" decoding=\"async\" width=\"658\" height=\"330\" src=\"https:\/\/SUMMALAI.COM\/wp-content\/uploads\/2021\/07\/adding_yyyy_mmm.png\" alt=\"\" class=\"wp-image-3459\" srcset=\"https:\/\/SUMMALAI.COM\/wp-content\/uploads\/2021\/07\/adding_yyyy_mmm.png 658w, https:\/\/SUMMALAI.COM\/wp-content\/uploads\/2021\/07\/adding_yyyy_mmm-300x150.png 300w\" sizes=\"(max-width: 658px) 100vw, 658px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>I got a question like this: Is it possible when saving a file in vba to add the current month\/year to the end of the filename with the format mmm\/yy? The code I have so far&#8230;.. &lt;code&gt;Workbooks(&#8220;test.xls&#8221;).SaveCopyAs (&#8220;C:\\xls files\\test.xls&#8221;)&lt;\/code&gt; I need the month\/year to be added to test.xls so that it looks like &#8220;test_Oct-07.xls&#8221; Let&#8217;s <a class=\"read-more\" href=\"https:\/\/SUMMALAI.COM\/?p=3458\">Read More<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[10,18],"tags":[782,781,783],"class_list":["post-3458","post","type-post","status-publish","format-standard","hentry","category-microsoft","category-microsoft-office","tag-add-month-and-year-to-filename","tag-add-month-year-to-filename","tag-adding-year-month-to-filename"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=\/wp\/v2\/posts\/3458","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3458"}],"version-history":[{"count":1,"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=\/wp\/v2\/posts\/3458\/revisions"}],"predecessor-version":[{"id":3460,"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=\/wp\/v2\/posts\/3458\/revisions\/3460"}],"wp:attachment":[{"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3458"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3458"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3458"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}