Das Programm sichert die aktuelle Word Datei in einem Unterverzeichnis. Die Sicherung wird mit einem Timestamp versehen. Das Makro ist in die normal.dot zu übernehmen und kann dann mittels Button in der Icon-Leiste verknüpft werden.
Sub Snapshot2Archive()
' Routine in Normal Dot speichern und via Toolbar verfügbar machen
On Error GoTo ErrorExit
Dim activePath As String
Dim activeName As String
Dim activeFile As String
Dim activeTarget As String
Dim activeArchiv As String
Dim categoryNo As String
' Sub-Verzeichnis zur Sicherung der Snapshots festlegen
activeArchiv = "archive"
activePath = ActiveDocument.Path
activeName = ActiveDocument.Name
activeFile = activePath & "\" & activeName
activeTarget = activePath & "\" & activeArchiv & "\" & Format(Date, "yyyymmdd") & "-" & Format(Time, "hhmmss") & "-" & activeName
ChDir (activePath & "\" & activeArchiv & "\")
ActiveDocument.SaveAs2 FileName:= _
activeTarget _
, FileFormat:=wdFormatXMLDocument, LockComments:=False, Password:="", _
AddToRecentFiles:=True, WritePassword:="", ReadOnlyRecommended:=False, _
EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False, SaveFormsData _
:=False, SaveAsAOCELetter:=False, CompatibilityMode:=14
ActiveDocument.Close
Documents.Open FileName:= _
activeFile _
, ConfirmConversions:=False, ReadOnly:=False, AddToRecentFiles:=False, _
PasswordDocument:="", PasswordTemplate:="", Revert:=False, _
WritePasswordDocument:="", WritePasswordTemplate:="", Format:= _
wdOpenFormatAuto, XMLTransform:=""
categoryNo = Str(Val(ActiveDocument.BuiltInDocumentProperties(wdPropertyCategory).Value) + 1)
ActiveDocument.BuiltInDocumentProperties(wdPropertyCategory).Value = categoryNo & " version sequence"
ActiveDocument.Save
MsgBox "Document snapshot was stored into sub-folder " & activeArchiv & "!", vbInformation, ActiveDocument.BuiltInDocumentProperties(wdPropertyCategory).Value
Exit Sub
ErrorExit:
If Err = 76 Then
MkDir (activePath & "\" & activeArchiv & "\")
Resume Next
Else
MsgBox Error(Err), vbInformation, "Fehlermeldung (" & LTrim(Str(Err)) & ")"
Resume Next
End If
End Sub