Content Controls on macOS with different locale / language

24 Views Asked by At

I have used this code to create a macro that inserts a DatePicker in a Word document on my Mac:

Sub AddDatePickerCC_GermanExt()
  Dim oCC As ContentControl
  Set oCC = ActiveDocument.ContentControls.Add(wdContentControlDate, Selection.Range)
  With oCC
    .DateCalendarType = wdCalendarWestern
    .DateDisplayFormat = "d. MMMM yyyy"
    .DateDisplayLocale = wdGerman
  End With
  Set oCC = Nothing
End Sub

Adapted from this guide: Content Controls for macOS

While this works when I have set my Word to German, it fails when the language of Word is changed to English (region is left to Germany).

The error says:

This calendar type is not available for the current date languange.

The debugger points to .DateCalendarType = wdCalendarWestern but changing this makes no sense, since the Mac's calendar is set to Gregorian. The field is inserted, but in the format 01/01/2024 and not as specified.

Any advice? Thank you already!

1

There are 1 best solutions below

0
QuestJonas On

I actually managed now. If anybody has the same problem, it is the order under With oCC

The correct code would be:

Sub AddDatePickerCC_GermanExt()
  Dim oCC As ContentControl
  Set oCC = ActiveDocument.ContentControls.Add(wdContentControlDate, Selection.Range)
  With oCC
    .DateDisplayFormat = "d. MMMM yyyy"
    .DateDisplayLocale = wdGerman
    .DateCalendarType = wdCalendarWestern
  End With
  Set oCC = Nothing
End Sub

It works correctly then.