PrivateSub Document_Open()
'
' Kopfnamen-Makro
' Aktualisiert die Bezeichnung in der Kopfzeile anhand des Pfads
' Erstellt 12.11.2007 von Markus Birth <mbirth@webwriters.de>
'
' WICHTIG!!!!
' Im Ordner mit den Abteilungsbüchern muss eine Datei
' .rootmarker.NichtLöschen.txt
' existieren, damit die Bezeichnung richtig gesetzt wird
Set fs = CreateObject("Scripting.FileSystemObject")
Dim FN
FN = ThisDocument.Name
FP = ThisDocument.Path
CRLF = Chr(13) & Chr(10)
HBTIT = "Evangelisches" & CRLF & "Waldkrankenhaus" & CRLF & "Spandau"
RootM = ".rootmarker.NichtLöschen.txt"
BeautyName = Left(FN, Len(FN) - 4)
' Find Rootmarker
IsFound = False
RMP = FP
DoIf (fs.FileExists(RMP & "\" & RootM)) Then
IsFound = TrueElse
pi = InStrRev(RMP, "\")
If (pi > 0) Then RMP = Left(RMP, pi - 1)
EndIfLoopUntil (IsFound Or pi = 0)
If (IsFound) Then' Root marker found in RMP, now find first folder
FF = Mid(FP, Len(RMP) + 1)
If (Left(FF, 1) = "\") Then FF = Mid(FF, 2)
If (InStr(FF, "\") <> 0) Then FF = Left(FF, InStr(FF, "\") - 1)
' remove digits or spaces from beginning of text
While (InStr("0123456789 .", Left(FF, 1)) <> 0)
FF = Mid(FF, 2)
Wend
AddProp "AbtTitel", FF & CRLF & HBTIT
Else
AddProp "AbtTitel", HBTIT
EndIfEndSubPrivateSub AddProp(PName, PVal)
' Fügt eine DokumentenVariable dem Dokument hinzu oder ändert eine bestehende
' Erstellt am 28.09.2005 von Markus Birth <mbirth@webwriters.de>
num = 0
ForEach e In ThisDocument.CustomDocumentProperties
If e.Name = PName Then num = 1
Next e
If num = 0 Then
ThisDocument.CustomDocumentProperties.Add PName, False, msoPropertyTypeString, PVal
Else
ThisDocument.CustomDocumentProperties(PName).Value = PVal
EndIfEndSub