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

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,344
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,344
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
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,833
Messages
5,833,893
Members
430,241
Latest member
Matty Se

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