VBA: Format Now() to yyyymmddHhNnSs

goldfish

Well-known Member
Joined
Aug 23, 2005
Messages
712
I got the formatting that I want down which is "yyyymmddHhNnSs", but I haven't be able to figure out which VBA function to use to change Now() from
Code:
7/26/2007 12:45:26 PM
to
Code:
20070726124526
Like I want it.


Further more I would like to Write code do do the following
Code:
Sub ArchiveFile()
If [File Test.zip already exists] Then
[Move Test.zip to Test.20070726124526.zip]
End If
End Sub
Thanks,
~Gold Fish
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Your title is almost the exact code you need.:)
Code:
Msgbox Format(Now(),"yyyymmddHhNnSs")
 
Upvote 0
Bah, Format! Duh, no wonder it didn't come up in my help search for "Date".

Thanks!

Part 2 anyone?
Code:
Sub ArchiveFile() 
If [File Test.zip already exists] Then 
[Move Test.zip to Test.20070726124526.zip] 
End If 
End Sub

Where 20070726124526 is the date modified of Test.zip?

Thanks,
~Gold Fish
 
Upvote 0
Well we would probably also need the path for that one.
Code:
If Dir("C:\File Test.Zip")<>"" Then
      Name "C:\File Test.Zip" As "C:\Test." &  Format(Now(),"yyyymmddHhNnSs") & ".Zip"
End If
 
Upvote 0
Throw in a little "FileDateTime" and I have myself some code!

Thanks Jonmo1 and Norie!

~Gold Fish
 
Upvote 0

Forum statistics

Threads
1,223,632
Messages
6,173,472
Members
452,516
Latest member
archcalx

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