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

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,286
Office Version
  1. 365
Platform
  1. Windows
Your title is almost the exact code you need.:)
Code:
Msgbox Format(Now(),"yyyymmddHhNnSs")
 

goldfish

Well-known Member
Joined
Aug 23, 2005
Messages
712
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
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,286
Office Version
  1. 365
Platform
  1. Windows
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
 

goldfish

Well-known Member
Joined
Aug 23, 2005
Messages
712
Throw in a little "FileDateTime" and I have myself some code!

Thanks Jonmo1 and Norie!

~Gold Fish
 

Watch MrExcel Video

Forum statistics

Threads
1,130,303
Messages
5,641,425
Members
417,209
Latest member
Agbarker

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
Top