Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 11-13-2023, 02:27 AM
gmayor's Avatar
gmayor gmayor is offline Run an ms word vba macro before a specific time Windows 10 Run an ms word vba macro before a specific time Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,144
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

The following should work. You will need to add a few lines to your macro and then call it from an autoexec macro in the same template.
Basically it checks whether the time is before 11 am when Word is opened. If it is, it then checks whether a custom document property exists and if it doesn't contain today's date it runs your macro, which updates the document property and saves the template.



Code:
Option Explicit

Sub AutoExec()
Dim oCP As DocumentProperty
Dim bProp As Boolean
    If Val(Format(Now, "hhmm")) < "1100" Then
        For Each oCP In ThisDocument.CustomDocumentProperties
            If oCP.Name = "AutoRunDate" Then
                If oCP.value = Date Then
                    bProp = True
                    Exit For
                End If
            End If
        Next oCP
        If bProp = False Then Call MyMacro
    End If
End Sub


Sub MyMacro()
Dim oCP As DocumentProperty
Dim bProp As Boolean
For Each oCP In ThisDocument.CustomDocumentProperties
    If oCP.Name = "AutoRunDate" Then
        oCP.value = Date
        bProp = True
        Exit For
    End If
Next oCP
If bProp = False Then
    ThisDocument.CustomDocumentProperties.Add Name:="AutoRunDate", _
        LinkToContent:=False, _
        value:=Date, _
        Type:=3
End If
ThisDocument.Save
MsgBox "Test"  'the rest of your macro code
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to navigate to specific point in line (Word 97) Genericname1111 Word 13 10-06-2019 08:54 PM
Run an ms word vba macro before a specific time Macro to select multiple sentences that contain a specific word MauiTruss Word VBA 7 10-03-2018 03:46 PM
Executing a Word macro only after a certain date & time rdross51 Word VBA 4 07-07-2017 06:29 AM
Help with Macro to Save Word File as PDF in Specific Location ekimisme Word VBA 1 06-07-2017 10:40 PM
Run an ms word vba macro before a specific time Excel Macro finding a specific word ducky831 Excel Programming 3 09-17-2015 01:36 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:24 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