Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #3  
Old 08-05-2021, 11:53 PM
Guessed's Avatar
Guessed Guessed is offline Please Help. Future date macro that updates automatically Windows 10 Please Help. Future date macro that updates automatically Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,185
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

It looks like you are using macros anyway so I would do this with Content Controls and macros in the ThisDocument module. See attached demo document.
The code used is shown below to go along with a bunch of Content Controls I put into the demo document.
Code:
Private Sub Document_ContentControlOnEnter(ByVal thisCC As ContentControl)
  If thisCC.Title = "Today" And thisCC.ShowingPlaceholderText Then
    If thisCC.XMLMapping.IsMapped Then
      thisCC.XMLMapping.CustomXMLNode.Text = Format(Now, thisCC.DateDisplayFormat)
    End If
  ElseIf thisCC.Title = "Stay Days" And thisCC.ShowingPlaceholderText Then
    thisCC.Range.Text = InputBox("Please input the number of days for the stay duration", "Stay Duration (in days)", "1")
  End If
End Sub

Private Sub Document_ContentControlOnExit(ByVal thisCC As ContentControl, Cancel As Boolean)
  Dim aCC As ContentControl, iDays As Integer, sDateFormat As String, dtEnd As Variant, sFormat As String
  If thisCC.Title = "Today" Then
    If Not thisCC.ShowingPlaceholderText Then
      iDays = InputBox("Please input the number of days for the stay duration", "Stay Duration (in days)", "1")
      For Each aCC In ActiveDocument.SelectContentControlsByTitle("Stay Days")
        aCC.Range.Text = iDays
      Next aCC
      sFormat = thisCC.DateDisplayFormat
      thisCC.DateDisplayFormat = "d MMM yyyy"
      dtEnd = DateAdd("d", iDays, thisCC.Range.Text)
      For Each aCC In ActiveDocument.SelectContentControlsByTitle("Exit Date")
        sDateFormat = aCC.DateDisplayFormat
        aCC.Range.Text = Format(dtEnd, sDateFormat)
      Next aCC
      thisCC.DateDisplayFormat = sFormat
    End If
  End If
End Sub
Attached Files
File Type: docm DateUpdater.docm (36.1 KB, 16 views)
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Preceding Day on Future Date.. ThorstenG Project 0 12-18-2017 06:14 AM
Please Help. Future date macro that updates automatically Date field - future date calculation + only business days neon4 Word 7 01-21-2016 02:21 PM
Please Help. Future date macro that updates automatically macro to automatically date sheet tab Jackie Excel Programming 13 05-24-2015 02:36 PM
Please Help. Future date macro that updates automatically VBA code for inserting a future date cosmopolitan Word VBA 1 08-14-2013 01:58 PM
Please Help. Future date macro that updates automatically Automatic date updates. WLVanS Word 12 01-29-2011 04:01 AM

Other Forums: Access Forums

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