Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
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
  #2  
Old 08-06-2021, 01:07 AM
MartyC MartyC is offline Please Help. Future date macro that updates automatically Windows 10 Please Help. Future date macro that updates automatically Office 2019
Novice
Please Help. Future date macro that updates automatically
 
Join Date: Aug 2021
Posts: 11
MartyC is on a distinguished road
Default Clarity

Ok folks, thanks for the replies. Just to clarify, i have a template, with both dates in relevant places multiple times. We have 21 rooms, but very often, most of the rooms will be occupied by the same people.

I have two folders, one for current service users, and another folder for to keep records for service users who have used the services in the past.

When a new resident comes in, I will open the template, fill their details in, national insurance etc and reason for homelessness, then drop it into the folder with the current users.

All the files can be selected and sent to the printer at once and if i get the dates going, it will save having opening up each file every day.

we work with a lot of drug and alcohol users and any time I can save at a computer helps us focus on more important things so that's why I' looking to steam line the process.

Here is a section where i have to do both dates, there are 4 other sections where I have to do this, multiply this by 21 and you can begin to see why I'm trying to solve this.

The current date is simple enough, but tomorrows date in red is where I need to get help.

Anyway, ill look into your kind replies and get back to let you know how I get on.
Attached Images
File Type: gif example.gif (64.1 KB, 32 views)

Last edited by MartyC; 08-06-2021 at 01:11 AM. Reason: Trying to add picture
Reply With Quote
  #3  
Old 08-06-2021, 07:50 AM
MartyC MartyC is offline Please Help. Future date macro that updates automatically Windows 10 Please Help. Future date macro that updates automatically Office 2019
Novice
Please Help. Future date macro that updates automatically
 
Join Date: Aug 2021
Posts: 11
MartyC is on a distinguished road
Default

This perfect, if i could get this to work. I really don't know what I'm doing.
Reply With Quote
Reply



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 08:29 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