![]() |
|
#1
|
|||
|
|||
|
I have a word file with a table as attached What is required is an equation that gives me the result of two cells (the Hijri date and the end date) as soon as I write the date of the letter, since the date is not automatically inserted and in the same format attached |
|
#2
|
||||
|
||||
|
Because of the Hijri date calculation, this is a task best performed using a macro and content controls. Save the attached as a macro enabled template and create a new document from it. The three content controls will be filled with the appropriate dates for the date the document is created. Note that your example appears to have the Hijri Date one day adrift according to the various on-line calculators, however this is not an area I am familiar with.
They code in the attached is as follows: Code:
Option Explicit
'Graham Mayor - https://www.gmayor.com - Last updated - 22 Dec 2021
Sub AutoNew()
AddDates
End Sub
Sub AddDates()
Dim oCC As ContentControl
For Each oCC In ActiveDocument.ContentControls
Select Case LCase(oCC.Title)
Case Is = "date"
oCC.Range.Text = Date
Case Is = "hijri date"
oCC.Range.Text = dateHijri(Date)
Case Is = "end date"
oCC.Range.Text = Format((Date + 3), "yyyy/mm/dd")
Case Else
End Select
Next oCC
End Sub
Private Function dateHijri(sDate As String) As String
Dim vVal As Variant
Dim dtHijri As Date
VBA.Calendar = vbCalGreg
If sDate <> vbNullString Then
On Error GoTo lbl_Exit
dtHijri = DateValue(sDate)
VBA.Calendar = vbCalHijri
dateHijri = dtHijri
End If
VBA.Calendar = vbCalGreg
Exit Function
lbl_Exit:
dateHijri = vbNullString
VBA.Calendar = vbCalGreg
End Function
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
#3
|
|||
|
|||
|
thank you
I would like the response to be no macro if possible Regarding the Hijri date, the problem can be solved later I ask how to add 3 days to the date of the letter |
|
#4
|
||||
|
||||
|
See https://www.gmayor.com/Zips/DateCalc.zip for information on using fields to add 3 days to a date. I don't know how to convert the Hijri date without using a macro.
The macro solution is simpler.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
#5
|
|||
|
|||
|
With apologies, I will explain what is required in a simpler way, see the attached file
cell D3 = value of cell D1+3 Cell D2 = the value of cell D1, but the date format changes to Hijri |
|
#6
|
||||
|
||||
|
Your explanation was simple enough before, but what you require is not as simple as you imagine. For example, if you refer to the document I linked the field construction required to add 3 days to the current date is
{QUOTE {SET Delay 3} {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)}} "{mm}-{dd}-{yy}" \@ "MM/dd/yyyy"} You cannot simply add 3 to the date or (say) 30th December + 3 would be 32nd December. You can insert date fields that will give the required values for today's date for the three dates (see attached), but it will not work with typed text dates. You cannot calculate text dates in this manner in a Word table. If you are not using date fields, the macro approach is still the most sensible option here.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Wish to delete letters to the right of the cursor in a Table cell, but whole cell is being deleted
|
vjvj123 | Word VBA | 12 | 09-27-2018 03:09 PM |
Clear all cell colors within a range starting at cell A8 and change row of active cell to yellow
|
FUGMAN | Excel Programming | 7 | 02-05-2017 08:37 AM |
| Pasting text from Excel cell into word without creating a table, and keeping the in-cell formatting | hanvyj | Excel Programming | 0 | 08-28-2015 01:15 AM |
Table with text that flows from cell to cell
|
hwrigley | Word Tables | 7 | 02-18-2014 02:59 AM |
| Auto-populate an MS Word table cell with text from a diff cell? | dreamrthts | Word Tables | 0 | 03-20-2009 01:49 PM |