View Single Post
 
Old 12-22-2021, 01:37 AM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,137
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 ofgmayor has much to be proud of
Default

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
Attached Files
File Type: docm Question2.docm (32.4 KB, 6 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