You can do it by storing the counter somewhere, ideally in the template containing the process you wish to count - here 'Main' - e.g. as follows.
I have included a macro to test and display the count.
Code:
Option Explicit
Public Function memory() As Integer
Dim oVar As Variable
Dim bVar As Boolean
For Each oVar In ThisDocument.Variables
If oVar.Name = "varMemory" Then
memory = oVar.Value
Exit For
End If
If Not bVar Then memory = 0
Next oVar
lbl_Exit:
Exit Function
End Function
Sub main()
Dim oVar As Variable
Dim bVar As Boolean
For Each oVar In ThisDocument.Variables
If oVar.Name = "varMemory" Then
oVar.Value = oVar.Value + 1
Exit For
End If
Next oVar
If Not bVar Then ThisDocument.Variables("varMemory").Value = 1
UpdateTemplate
lbl_Exit:
Exit Sub
End Sub
Sub UpdateTemplate()
'Graham Mayor
Dim bBackup As Boolean
bBackup = Options.CreateBackup
Options.CreateBackup = False
ThisDocument.Save
Options.CreateBackup = bBackup
lbl_Exit:
Exit Sub
End Sub
Sub Test()
MsgBox memory
lbl_Exit:
Exit Sub
End Sub