If you’re prepared to use a Macro solution, you could try this solution. The idea is to create a Sub that will be called each time the document is opened StartUp(). It will call a Function called DocModifiedToday() to see if you’ve modified the document today (obviously). This way you won’t be nagged every time you open your document. If you haven’t modified the document, then StartUp() calls UpdateTOC() to – you guessed it.
Here’s the code:
Sub UpdateTOC()
Dim oIndexes, oIndex As Object
oIndexes = ThisComponent.getDocumentIndexes()
For i = 0 To oIndexes.getCount() - 1
oIndex = oIndexes.getByIndex(i)
If oIndex.supportsService("com.sun.star.text.ContentIndex") Then
oIndex.update()
Exit For
End If
Next
End Sub
Function DocModifiedToday() As Boolean
Dim ModDate As Object
Dim LastMod As Date
ModDate = ThisComponent.DocumentProperties.ModificationDate
LastMod = DateSerial(ModDate.Year, ModDate.Month, ModDate.Day)
DocModifiedToday = (LastMod = DateValue(Now()))
End Function
Sub StartUp()
' Check to see if Doc has aleady been modified TODAY. If so, we skip TOC update
If DocModifiedToday() = True Then Exit Sub
If (Day(Now) = 1) AND (Month(Now) > 1) Then ' Do on the 1st of each month but not January
Answer = MsgBox("Update the TOC?", 32 + 4, "Start Up") ' Ask the user if he wants to update the TOC
If Answer = 6 Then UpdateTOC()
End If
End Sub
Other options you can go with are:
If(WeekDay(Now) = 1) Then ’ Every Monday (Or SUN = 0 to SAT = 6)
Or you could simply remove the If … Else and just do it each day:
Answer = MsgBox("Update the TOC?", 32 + 4, "Start Up") ' Ask the user if he wants to update the TOC
If Answer = 6 Then UpdateTOC()
The DocModifiedToday() Function is just anti-nag coding. Once you’ve actually edited your document in some way, even just re-saving it, you won’t be asked again that day whether you want to update the TOC. (That would be nagging.)
To make it all work, you need to then set StartUp() to be called when the document is opened:
Tools → Customize → Events
Set Open Document to call your StartUp() Sub.
Hope this helps.