Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-05-2021, 06:24 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 Please Help. Future date macro that updates automatically

Hi All

New user here and complete noob to macros, so please forgive me if I don't have the right terminology.

I work for a homeless services organisation and we have a lot of men who stay with us each night. One of our partner organisations have to receive paperwork of us each day. ( why this has not went digital, i don't know )

Anyway, each day, the staff have to print out about 30 copes of this 7 page form, that has various fields, and the homeless guys details have to be hand written in etc and its very time consuming. There are also many different fields for todays date, and tomorrows date (indicating an overnight stay).

Unfortunately, we are told to use these forms by a parent organisation so we can't really simplify things as it is all templates.

However, I have figured out a way to make things faster to process and save a lot of writing, but I have an issue with just one thing, and this is where you lovely folk come in.

There is a section that asks for date of stay and date of departure. I can use the insert date and update automatically function, and that works fine. As for tomorrows date , I can find the macro that lets me insert todays date plus 1. Now when I opened one of the documents today to check, todays date was showing where it should, indicating the insert date and time function is working as it should, however, the macro didn't update automatically, to show tomorrows date, where its needed, and I'm wondering, can there be something added to the one I have, to make it update automatically also/ in other words, any time I open the document, it will always show tomorrows date where it should? The code I have is as follows...

Sub InsertFutureOrPastDate()
Dim strNumberOfDays As String

' Input the number of days you want to insert from today to the future or past date.
strNumberOfDays = InputBox("Please input the number of days you want to insert", "future or past date", "Input here.For exemple,input 1 to insert the date of tomorrow")
' Insert the future or past date according to the inputed number of days
If strNumberOfDays <> "" Then
Selection.TypeText Text:=Format(Date + strNumberOfDays, "dd/mm/yyyy")
End If
End Sub

Any help or advice would be great.

Thank you so much in advance...


Marty
Reply With Quote
  #2  
Old 08-05-2021, 08:55 PM
gmayor's Avatar
gmayor gmayor is offline Please Help. Future date macro that updates automatically Windows 10 Please Help. Future date macro that updates automatically Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,106
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 of
Default

If this is a document that you are opening and printing then a Date field will update when the document is opened as it reads the system date from the computer. For tomorrow's date, you need a calculated date field and that is covered by Paul Edstein's excellent work on dates linked from Insert a past or future date

The example shows a Delay of 14 days and refers to the CREATEDATE field (which would be appropriate if the document was a template and you were creating new documents each time) Change the instances of CREATEDATE to DATE and the Delay to 1.
__________________
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
  #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: 3,977
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, 13 views)
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #4  
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, 25 views)

Last edited by MartyC; 08-06-2021 at 01:11 AM. Reason: Trying to add picture
Reply With Quote
  #5  
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
  #6  
Old 08-06-2021, 08:39 PM
gmayor's Avatar
gmayor gmayor is offline Please Help. Future date macro that updates automatically Windows 10 Please Help. Future date macro that updates automatically Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,106
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 of
Default

Did you even read the link I posted? Download the document I referred to and on page 7 you will see a heading 'Calculate a day, date, month and year, using n days delay'. Select the date in that section. Right click and 'toggle field codes'. Copy the code and paste to where you want the calculated date. Change the delay to 1 and the switch to "dd/MM/yyyy"

{QUOTE
{SET Delay 14}
{SET a{=INT((14-{DATE \@ M})/12)}}
{SET b{={DATE \@ yyyy}+4800-a}}
{SET c{={DATE \@ M}+12*a-3}}
{SET d{DATE \@ d}}
{SET jd{=d+INT((153*c+2)/5)+365*b+INT(b/4)-INT(b/100)+INT(b/400)-32045+Delay}}
{SET e{=INT((4*(jd+32044)+3)/146097)}}
{SET f{=jd+32044-INT(146097*e/4)}}
{SET g{=INT((4*f+3)/1461)}}
{SET h{=f-INT(1461*g/4)}}
{SET i{=INT((5*h+2)/153)}}
{SET dd{=h-INT((153*i+2)/5)+1}}
{SET mm{=i+3-12*INT(i/10)}}
{SET yy{=100*e+g-4800+INT(i/10)}}
"{dd}-{mm}-{yy}" \@ "dddd, d MMMM yyyy"}
__________________
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
  #7  
Old 08-09-2021, 04:10 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

Sorry, I Did read and then downloaded the next document. Ill try this today.
Quote:
Originally Posted by gmayor View Post
Did you even read the link I posted? Download the document I referred to and on page 7 you will see a heading 'Calculate a day, date, month and year, using n days delay'. Select the date in that section. Right click and 'toggle field codes'. Copy the code and paste to where you want the calculated date. Change the delay to 1 and the switch to "dd/MM/yyyy"

{QUOTE
{SET Delay 14}
{SET a{=INT((14-{DATE \@ M})/12)}}
{SET b{={DATE \@ yyyy}+4800-a}}
{SET c{={DATE \@ M}+12*a-3}}
{SET d{DATE \@ d}}
{SET jd{=d+INT((153*c+2)/5)+365*b+INT(b/4)-INT(b/100)+INT(b/400)-32045+Delay}}
{SET e{=INT((4*(jd+32044)+3)/146097)}}
{SET f{=jd+32044-INT(146097*e/4)}}
{SET g{=INT((4*f+3)/1461)}}
{SET h{=f-INT(1461*g/4)}}
{SET i{=INT((5*h+2)/153)}}
{SET dd{=h-INT((153*i+2)/5)+1}}
{SET mm{=i+3-12*INT(i/10)}}
{SET yy{=100*e+g-4800+INT(i/10)}}
"{dd}-{mm}-{yy}" \@ "dddd, d MMMM yyyy"}
Reply With Quote
  #8  
Old 08-09-2021, 05:21 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

Okay, I can only get the following message. I'm sure its something simple, but I really have no idea what I'm doing.

Error! Too many picture switches defined.

Here is what the code looks like to me. I'm sure you guys can spot the errors.

I do appreciate your time
Attached Images
File Type: gif Code.gif (53.3 KB, 21 views)
Reply With Quote
  #9  
Old 08-09-2021, 05:52 AM
gmayor's Avatar
gmayor gmayor is offline Please Help. Future date macro that updates automatically Windows 10 Please Help. Future date macro that updates automatically Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,106
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 of
Default

It looks like you have pasted text and not the code from the document, and you have pasted within your date field and not after it. Post the document or a link to it.
__________________
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
  #10  
Old 08-09-2021, 07:02 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

Quote:
Originally Posted by gmayor View Post
It looks like you have pasted text and not the code from the document, and you have pasted within your date field and not after it. Post the document or a link to it.
Okay, I think I have done it right.

Thanks
Attached Files
File Type: docx Housing Benefit form Template.docx (39.0 KB, 17 views)
Reply With Quote
  #11  
Old 08-09-2021, 08:36 PM
gmayor's Avatar
gmayor gmayor is offline Please Help. Future date macro that updates automatically Windows 10 Please Help. Future date macro that updates automatically Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,106
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 of
Default

Try the attached. If you are using Word 2010 or later, I would suggest using content controls for the check boxes and text inputs - see
https://www.gmayor.com/insert_content_control_addin.htm
Attached Files
File Type: docx Housing Benefit form Template.docx (40.0 KB, 11 views)
__________________
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
  #12  
Old 08-10-2021, 01:49 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

Quote:
Originally Posted by gmayor View Post
Try the attached. If you are using Word 2010 or later, I would suggest using content controls for the check boxes and text inputs - see
https://www.gmayor.com/insert_content_control_addin.htm
Okay ill try. A little about me, so you can see why I appreciate your patience, I do maintenance for these guys, and i can strip an engine down blindfolded and put it back together, but when it comes to this type of thing, its all new, so ill go and try what you said but i might need a step by step.

Thanks again
Reply With Quote
  #13  
Old 08-10-2021, 01:55 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

That seems to be perfect. If I print that off tomorrow, will the dates your helped me with be updated automatically?
Reply With Quote
  #14  
Old 08-10-2021, 04:34 AM
gmayor's Avatar
gmayor gmayor is offline Please Help. Future date macro that updates automatically Windows 10 Please Help. Future date macro that updates automatically Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,106
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 of
Default

Don't worry about the content controls. Work with what you are comfortable with.

As for the dates, see what happens tomorrow
__________________
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
  #15  
Old 08-10-2021, 05:36 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
Talking Thank You

Thank you so much
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 05:40 AM.


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