Sub
BearbeiteDateien()
Dim
folderPath
As
String
Dim
templatePathPortrait
As
String
Dim
templatePathLandscape
As
String
Dim
templateDocPortrait
As
Document
Dim
templateDocLandscape
As
Document
Dim
file
As
String
folderPath = "C:\Users\sbutz\Desktop\Test docx neu\"
templatePathPortrait =
"C:\Users\sbutz\Desktop\Fußzeile Hochformat.docx"
templatePathLandscape =
"C:\Users\sbutz\Desktop\Fußzeile Querformat.docx"
Set
templateDocPortrait = Documents.Open(templatePathPortrait)
Set
templateDocLandscape = Documents.Open(templatePathLandscape)
file = Dir(folderPath &
"\*.doc*"
)
Do
While
file <>
""
BearbeiteWordDatei folderPath & "\" & file, templateDocPortrait, templateDocLandscape
file = Dir
Loop
templateDocPortrait.Close SaveChanges:=
False
templateDocLandscape.Close SaveChanges:=
False
Set
templateDocPortrait =
Nothing
Set
templateDocLandscape =
Nothing
MsgBox
"Fertig!"
End
Sub
Sub
BearbeiteWordDatei(filePath
As
String
, templateDocPortrait
As
Document, templateDocLandscape
As
Document)
Dim
doc
As
Document
Dim
orientation
As
String
Set
doc = Documents.Open(filePath)
orientation = doc.PageSetup.orientation
If
orientation = wdOrientPortrait
Then
templateDocPortrait.Sections(1).Footers(wdHeaderFooterPrimary).Range.Copy
ElseIf
orientation = wdOrientLandscape
Then
templateDocLandscape.Sections(1).Footers(wdHeaderFooterPrimary).Range.Copy
End
If
doc.Sections(1).Footers(wdHeaderFooterPrimary).Range.Paste
doc.Save
doc.Close SaveChanges:=
False
Set
doc =
Nothing
End
Sub