View Single Post
 
Old 07-25-2024, 05:42 AM
annguye2 annguye2 is offline Mac OS X Office 2021
Novice
 
Join Date: Jul 2024
Posts: 22
annguye2 is on a distinguished road
Default

Hi,
I am trying to copy the footer from one document to another.
And here is what my code (I only try to copy the first page footer)

Sub CopyFootersForFirstPage() ' works
Dim docTemplate As Document
Dim strTemplate As String
Dim footer1 As HeaderFooter
Dim footer2 As HeaderFooter
Dim doc As Document
Application.ScreenUpdating = False
Set doc = ActiveDocument
strTemplate = "Some.docx" ' successfully open
Set docTemplate = Documents.Open(strTemplate) ' successfully open
Set footer1 = docTemplate.Sections(1).Footers(wdHeaderFooterFirs tPage)
Set footer2 = doc.Sections(1).Footers(wdHeaderFooterFirstPage)

footer1.Range.Copy
'Debug.Print "FootnFORE COPY first page : " & footer1.Range.Text
footer2.Range.Paste
Debug.Print "Foot2: " & footer2.Range.Text ' foot2 is printed in immeidate windows
'Set footer1 = Nothing
'Set footer2 = Nothing
' Set footer1 = docTemplate.Sections(1).Footers(wdHeaderFooterFirs tPage)
' Set footer2 = doc.Sections(1).Footers(wdHeaderFooterPrimary)


' Set footer1 = docTemplate.Sections(1).Footers(wdHeaderFooterPrim ary)
' Set footer2 = doc.Sections(1).Footers(wdHeaderFooterPrimary)
Application.ScreenUpdating = True
docTemplate.Close False

End Sub

it prints out the footers (target doc) but it's not display in on the doc. Can you please point me out why?
Thanks,
An Nguyen
Reply With Quote