Hallo,
ich habe die Word Datei "test docprop" erstellt. Darin sind zwei Felder, die über Document properties gefüllt werden: "test" und "ende".
Mit dem Klick auf einen Button erstelle ich ein Word Dokument, in das ich eine Tabelle einfüge, die mit der Bezeichnung der document Properties und den dazugehörigen Werten gefüllt wird. Die Datei bleibt geöffnet
In dem Dokument "test docprop" gibt es einen weiteren Button, mit dem man die Document Properties in das Dokument importieren kann.
Hierbei habe ich ein Problem.
Ich dachte, für das aktive Dokument("test docprop") können die werte der customdocumentproperties aus der tabelle aus dem erstellten Dokument "document Properties" einfach übernommen werden.
Aber hier bekomme ich immer Fehlermeldungen.
Hier mein Code.
Vielen Dank im Voraus für eure Unterstützung!
------------------------------------------------------------------------------------------------------------
Private Sub DocProperties_kopieren_Click()
Dim wrdApp As Object
Dim wrdDoc As Object
Dim i As Integer
'Create word document
Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True
Set wrdDoc = wrdApp.Documents.Add
'Fill word document
Call FillWordDoc(wrdDoc)
'Save document
FullName = Application.ActiveDocument.Path & "\" & "Document Properties.rtf"
With wrdDoc
If Dir(FullName) <> "" Then
Kill FullName
End If
.SaveAs FileName:=FullName, FileFormat:=wdFormatRTF
'.Close ' close the document
End With
End Sub
Sub FillWordDoc(Doc As Object)
Doc.Content.InsertParagraphAfter
'Create header table
Doc.Content.InsertParagraphAfter
Doc.Content.InsertParagraphAfter
pos = Doc.Content.End
Doc.Tables.Add Range:=Doc.Range(pos - 1, pos - 1), numrows:=23, numcolumns:=2, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:=wdAutoFitContent
'Fill header table
Doc.Tables.Item(1).Cell(1, 1).Range.Text = "test"
Doc.Tables.Item(1).Cell(1, 2).Range.Text = ActiveDocument.CustomDocumentProperties("test").Value
Doc.Tables.Item(1).Cell(2, 1).Range.Text = "ende"
Doc.Tables.Item(1).Cell(2, 2).Range.Text = ActiveDocument.CustomDocumentProperties("ende").Value
End Sub
Private Sub DocProperties_importieren_Click()
With ActiveDocument
Dim Doc As Object
Doc = Application.ActiveDocument.Path & "\" & "Document Properties.rtf"
.CustomDocumentProperties("test").Value = Doc.Tables.Item(1).Cell(1, 2).Range.Text
.CustomDocumentProperties("ende").Value = Doc.Tables.Item(1).Cell(2, 2).Range.Text
End With
End Sub
--------------------------------------------------------------------------------------------------------- |