![]() |
|
|
|
#1
|
||||
|
||||
|
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
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
|
#2
|
|||
|
|||
|
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. Last edited by MartyC; 08-06-2021 at 01:11 AM. Reason: Trying to add picture |
|
#3
|
|||
|
|||
|
This perfect, if i could get this to work. I really don't know what I'm doing.
|
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Preceding Day on Future Date.. | ThorstenG | Project | 0 | 12-18-2017 06:14 AM |
Date field - future date calculation + only business days
|
neon4 | Word | 7 | 01-21-2016 02:21 PM |
macro to automatically date sheet tab
|
Jackie | Excel Programming | 13 | 05-24-2015 02:36 PM |
VBA code for inserting a future date
|
cosmopolitan | Word VBA | 1 | 08-14-2013 01:58 PM |
Automatic date updates.
|
WLVanS | Word | 12 | 01-29-2011 04:01 AM |