I believe you have missed the significance about what I told you yesterday about using the numeric equivalents of Word commands when using late binding to Word i.e. those beginning 'wd' and in this instance wdHeaderFooterPrimary.
However I would have written it as follows, which does not produce an error.
Code:
Private Sub CommandButton1_Click()
Dim MSWord As Object
Dim oDoc As Object
Dim oRng As Object
Dim Datei As String
Dim pdfName As String
Set MSWord = CreateObject("Word.Application")
MSWord.Visible = True
Datei = "D:\WordTest.doc"
pdfName = "D:\WordTest.pdf"
Set oDoc = MSWord.Documents.Add
Set oRng = oDoc.Range
With oRng
.Collapse 1
.Text = "Text" & vbCr
.Font.Name = "Helvetica"
.Font.Size = 20
.Font.Color = 255
.Font.Bold = True
.Font.Italic = True
.Collapse 0
.InsertBreak 2
End With
With oDoc.Sections(1)
.Headers(1).Range.Text = "Header text"
.Footers(1).Range.Text = "Footer text"
End With
oDoc.SaveAs Datei
oDoc.ExportAsFixedFormat _
OutputFileName:=pdfName, _
ExportFormat:=17, _
OpenAfterExport:=False, _
OptimizeFor:=0, _
Range:=0, _
Item:=0, _
IncludeDocProps:=False, _
KeepIRM:=True, _
CreateBookmarks:=0, _
DocStructureTags:=True, _
BitmapMissingFonts:=True, _
UseISO19005_1:=False
oDoc.Close
MSWord.Quit
Set MSWord = Nothing
Set oDoc = Nothing
Set oRng = Nothing
End Sub