#1
|
|||
|
|||
Adding current time to VBA
I have the following which works fine but I'm trying to add hour,minute and second to dd MMM yyyy but I don't know how: Code:
Sub SaveNumberedVersion() 'Graham Mayor 15 Jan 2006 'Completely Revised 18 January 2011 'to store count in a document variable 'and improve document type handling Dim strVer As String Dim strDate As String Dim strPath As String Dim strFile As String Dim oVars As Variables Dim strFileType As WdDocumentType Dim strVersionName As String Dim intPos As Long Dim sExt As String Set oVars = ActiveDocument.Variables strDate = Format((Date), "dd MMM yyyy") With ActiveDocument On Error GoTo CancelledByUser If Len(.Path) = 0 Then 'No path means document not saved .Save 'So save it End If strPath = .Path 'Get path strFile = .Name 'Get document name End With intPos = InStr(strFile, " - ") 'Mark the version number sExt = Right(strFile, Len(strFile) - InStrRev(strFile, ".do")) If intPos = 0 Then 'No version number intPos = InStrRev(strFile, ".do") 'Mark the extension instead End If strFile = Left(strFile, intPos - 1) 'Strip the extension or version number Select Case LCase(sExt) 'Determine file type by extension Case Is = "doc" strFileType = 0 Case Is = "docx" strFileType = 12 Case Is = "docm" strFileType = 13 Case Is = "dot" strFileType = 1 Case Is = "dotx" strFileType = 14 Case Is = "dotm" strFileType = 15 End Select Start: 'Get Registry Data On Error Resume Next 'No entry in registry will flag an error strVer = oVars("varVersion").Value If strVer = "" Then 'Variable does not exist oVars("VarVersion").Value = "0" 'So create it GoTo Start: End If On Error GoTo 0 strVer = Val(strVer) + 1 'Increment number oVars("varVersion").Value = strVer 'Define the new version filename strVersionName = strPath & "\" & strFile & " - " & strDate & _ " - Version " & Format(Val(strVer), "00#") _ & Chr(46) & sExt 'and save a copy of the file with that name ActiveDocument.SaveAs strVersionName, strFileType Exit Sub CancelledByUser: 'Error handler MsgBox "Cancelled By User", , "Operation Cancelled" End Sub |
#2
|
|||
|
|||
strDate = Format((Date), "yyyy.MM.dd ") & Format((Time), "hhmm") 'colon/dwukropek not allowed
|
#3
|
||||
|
||||
You could just change:
strDate = Format((Date), "dd MMM yyyy") to, say: strDate = Format(Now, "dd MMM yyyy @ hh mm ss")
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#4
|
|||
|
|||
I added but it shows 00 00 00
|
#5
|
||||
|
||||
Quote:
(Date) to: Now ?
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#6
|
|||
|
|||
My bad! Thank you so much. It's solved.
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Table adding cells to previous page with room still on current page. | gedet | Word | 1 | 01-03-2018 10:35 AM |
adding and subtracting time on timesheet | renny0927 | Excel | 1 | 03-09-2017 01:07 PM |
Automatically Delete Slides based on current time | Pacman52 | PowerPoint | 2 | 07-16-2015 05:30 AM |
Create check box to insert current time | dougdrex | Excel | 1 | 12-07-2014 07:52 PM |
Current time keyboard shortcut | jbwenu | Excel | 2 | 02-05-2013 06:56 AM |