Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-15-2019, 06:45 AM
ArviLaanemets ArviLaanemets is offline Calculate week in Word document based on date entered into same document Windows 8 Calculate week in Word document based on date entered into same document Office 2016
Expert
Calculate week in Word document based on date entered into same document
 
Join Date: May 2017
Posts: 869
ArviLaanemets has much to be proud ofArviLaanemets has much to be proud ofArviLaanemets has much to be proud ofArviLaanemets has much to be proud ofArviLaanemets has much to be proud ofArviLaanemets has much to be proud ofArviLaanemets has much to be proud ofArviLaanemets has much to be proud ofArviLaanemets has much to be proud of
Default Calculate week in Word document based on date entered into same document

Hi


Into Word document, document date (in format dd.mm.yyyy) is entered. Elsewhere in same document I need an ISO weeknumber of this date displayed. Probably an UDF must be defined to calculate it - something like (on fly)
Code:
Public Function WeekNo(parDate As Date) As Integer
    WeekNo = DatePart(ww, parDate, 2, 2)
End Function
Ideally, in case the date is edited, the weeknumber in document must update too.


Is this possible?
a) in regular Word document;
b) in Word template only.
Reply With Quote
  #2  
Old 11-15-2019, 10:07 AM
Charles Kenyon Charles Kenyon is offline Calculate week in Word document based on date entered into same document Windows 10 Calculate week in Word document based on date entered into same document Office 2016
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,083
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

I do not believe I can quickly accomplish what you want.


I would store your week number in a document variable and use the Document Variable field to display it.


You need something to trigger upon changing the date. I believe if this is a date picker content control you can do this. You would want it to also update any document variable fields in the document after updateing the variable.


Just some thoughts. I am a dabbler. There are real programmers who frequent this forum.


I am moving this to the vba forum.
Reply With Quote
  #3  
Old 11-15-2019, 06:30 PM
Guessed's Avatar
Guessed Guessed is offline Calculate week in Word document based on date entered into same document Windows 10 Calculate week in Word document based on date entered into same document Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
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

In your Word document, put two content controls
Date Picker Content Control: give it a title of "TheDate"
Plain text Content Control: give it a title of "TheWeek"

Then in your ThisDocument module, add this code
Code:
Private Sub Document_ContentControlOnExit(ByVal aCC As ContentControl, Cancel As Boolean)
  Dim aDate As Date
  If aCC.Title = "TheDate" Then
    aDate = CDate(aCC.Range.Text)
    ActiveDocument.SelectContentControlsByTitle("TheWeek")(1).Range.Text = DatePart("ww", aDate, 2, 2)
  End If
End Sub
Then you can change the date in the TheDate CC and when you move the cursor out, the calculated result will appear in the TheWeek CC.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #4  
Old 11-16-2019, 11:10 AM
ArviLaanemets ArviLaanemets is offline Calculate week in Word document based on date entered into same document Windows 8 Calculate week in Word document based on date entered into same document Office 2016
Expert
Calculate week in Word document based on date entered into same document
 
Join Date: May 2017
Posts: 869
ArviLaanemets has much to be proud ofArviLaanemets has much to be proud ofArviLaanemets has much to be proud ofArviLaanemets has much to be proud ofArviLaanemets has much to be proud ofArviLaanemets has much to be proud ofArviLaanemets has much to be proud ofArviLaanemets has much to be proud ofArviLaanemets has much to be proud of
Default

Thanks!

I'll try this out at Monday.
Reply With Quote
  #5  
Old 11-18-2019, 12:25 AM
ArviLaanemets ArviLaanemets is offline Calculate week in Word document based on date entered into same document Windows 8 Calculate week in Word document based on date entered into same document Office 2016
Expert
Calculate week in Word document based on date entered into same document
 
Join Date: May 2017
Posts: 869
ArviLaanemets has much to be proud ofArviLaanemets has much to be proud ofArviLaanemets has much to be proud ofArviLaanemets has much to be proud ofArviLaanemets has much to be proud ofArviLaanemets has much to be proud ofArviLaanemets has much to be proud ofArviLaanemets has much to be proud ofArviLaanemets has much to be proud of
Default

Quote:
Originally Posted by Guessed View Post
In your Word document ...

Hi


It worked, but I didn't get full information last week, so I had to modify a bit


The document is printed out when a delivery is sent. The date is inserted automatically whenever the document is opened (the field is created using Insert > Date and Time). So instead of Document_ContentControlOnExit() I had to use
Code:
Private Sub Document_Open()
  
    ActiveDocument.SelectContentControlsByTitle("TheWeek")(1).Range.Text = DatePart("ww", Date, 2, 2)

End Sub
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calculate week in Word document based on date entered into same document split word document based on bookmarks with each new document title of the bookmark megatronixs Word VBA 9 09-05-2020 02:29 PM
data entered in one workbook should be updated in other relevant workbook based on the date vedha Excel 0 04-24-2015 08:45 PM
calculate date if date entered in cell, do nothing if blank ConfuddledOne Excel 3 11-07-2014 09:37 AM
Calculate week in Word document based on date entered into same document Formula to auto calculate Day of the week based on Date prasad@dmci.ca Excel 1 11-29-2011 01:05 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:48 PM.


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