Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-13-2018, 12:31 AM
blackroz blackroz is offline Adding current time to VBA Windows XP Adding current time to VBA Office 2007
Novice
Adding current time to VBA
 
Join Date: Nov 2015
Posts: 5
blackroz is on a distinguished road
Exclamation 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

Reply With Quote
  #2  
Old 01-13-2018, 02:04 AM
maniek maniek is offline Adding current time to VBA Windows XP Adding current time to VBA Office 2007
Novice
 
Join Date: Dec 2014
Posts: 3
maniek is on a distinguished road
Default

strDate = Format((Date), "yyyy.MM.dd ") & Format((Time), "hhmm") 'colon/dwukropek not allowed
Reply With Quote
  #3  
Old 01-13-2018, 02:06 AM
macropod's Avatar
macropod macropod is offline Adding current time to VBA Windows 7 64bit Adding current time to VBA Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #4  
Old 01-13-2018, 02:22 AM
blackroz blackroz is offline Adding current time to VBA Windows XP Adding current time to VBA Office 2007
Novice
Adding current time to VBA
 
Join Date: Nov 2015
Posts: 5
blackroz is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
You could just change:
strDate = Format((Date), "dd MMM yyyy")
to, say:
strDate = Format(Now, "dd MMM yyyy @ hh mm ss")
I added but it shows 00 00 00
Reply With Quote
  #5  
Old 01-13-2018, 02:40 AM
macropod's Avatar
macropod macropod is offline Adding current time to VBA Windows 7 64bit Adding current time to VBA Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by blackroz View Post
Quote:
Originally Posted by macropod View Post
You could just change:
strDate = Format((Date), "dd MMM yyyy")
to, say:
strDate = Format(Now, "dd MMM yyyy @ hh mm ss")
I added but it shows 00 00 00
And did you change:
(Date)
to:
Now
?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #6  
Old 01-13-2018, 04:03 AM
blackroz blackroz is offline Adding current time to VBA Windows 7 64bit Adding current time to VBA Office 2010 64bit
Novice
Adding current time to VBA
 
Join Date: Nov 2015
Posts: 5
blackroz is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
And did you change:
(Date)
to:
Now
?
My bad! Thank you so much. It's solved.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding current time to VBA 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
Adding current time to VBA 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

Other Forums: Access Forums

All times are GMT -7. The time now is 03:13 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft