Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #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
 



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 01:28 PM.


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