Vorlage beim Schließen löschen (VBA)

DerJo, Dienstag, 19.12.2017, 17:36 (vor 303 Tagen) @ DerJo

Hier die Lösung mit Hilfe einer Textmarke "loc":

 
Private Sub Document_Close()
 
            If ActiveDocument.Type = wdTypeTemplate Then
 
                Dim locb As String
                Dim cRange As Range
 
                If ActiveDocument.Bookmarks.Exists("loc") Then
                Set cRange = ActiveDocument.Bookmarks("loc").Range
                    locb = cRange.Text
                End If
                With ActiveDocument.Bookmarks
                    .Add Range:=cRange, Name:="loc"
                End With
 
                SetAttr locb, vbNormal
 
                Kill locb
 
            Else:
 
                Dim bRange As Range
 
                If ThisDocument.Bookmarks.Exists("loc") Then
                Set bRange = ThisDocument.Bookmarks("loc").Range
                    bRange.Text = ThisDocument.FullName
                End If
                With ThisDocument.Bookmarks
                    .Add Range:=bRange, Name:="loc"
                End With
 
                ActiveDocument.AttachedTemplate.Save
 
                Dim loca As String
                loca = ThisDocument.FullName
 
                ActiveDocument.AttachedTemplate = ""
                ActiveDocument.Saved = True
 
                Documents.Add Template:=loca, NewTemplate:=True
 
                Application.Quit
 
            End If
 
End Sub
 

gesamter Thread:

 RSS-Feed dieser Diskussion

powered by my little forum