Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-08-2021, 02:49 PM
Guessed's Avatar
Guessed Guessed is offline Converting the headers & footers into body Windows 10 Converting the headers & footers into body Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,176
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

I don't know how to convert VBA code to Python but this should give you an idea on how you could copy the headers and footers into the body of the document.
Code:
Sub HFExtractor()
  Dim aSect As Section, aHF As HeaderFooter, aRng As Range
  For Each aSect In ActiveDocument.Sections
    For Each aHF In aSect.Headers
      Set aRng = aSect.Range
      aRng.Collapse Direction:=wdCollapseEnd
      aRng.FormattedText = aHF.Range.FormattedText
    Next aHF
    For Each aHF In aSect.Footers
      Set aRng = aSect.Range
      aRng.Collapse Direction:=wdCollapseEnd
      aRng.FormattedText = aHF.Range.FormattedText
    Next aHF
  Next aSect
End Sub

__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #2  
Old 06-08-2021, 11:21 PM
CaptainCsaba CaptainCsaba is offline Converting the headers & footers into body Windows 10 Converting the headers & footers into body Office 2016
Novice
Converting the headers & footers into body
 
Join Date: Jun 2021
Posts: 4
CaptainCsaba is on a distinguished road
Default

Quote:
Originally Posted by Charles Kenyon View Post
Try opening directly in Word and using Word to convert one.
Unfortunately it has the same result.

Quote:
Originally Posted by Guessed View Post
I don't know how to convert VBA code to Python but this should give you an idea on how you could copy the headers and footers into the body of the document.
Code:
Sub HFExtractor()
  Dim aSect As Section, aHF As HeaderFooter, aRng As Range
  For Each aSect In ActiveDocument.Sections
    For Each aHF In aSect.Headers
      Set aRng = aSect.Range
      aRng.Collapse Direction:=wdCollapseEnd
      aRng.FormattedText = aHF.Range.FormattedText
    Next aHF
    For Each aHF In aSect.Footers
      Set aRng = aSect.Range
      aRng.Collapse Direction:=wdCollapseEnd
      aRng.FormattedText = aHF.Range.FormattedText
    Next aHF
  Next aSect
End Sub
I can call VBA codes from Python so they are definitely useful. I ran your code and it does extract headers just as needed. Only problem is that they all get added in bulk at the beginning of the next section. I need to retain their original position as much as possible (at least so they come after the text the come after in the PDF).

Might be a stupid idea as I am unfamiliar with how Word works, but can we for example get the x,y coordinates of these paragraphs and insert text "above them". Or something similar so we can keep the position as closely as possible?
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting the headers & footers into body headers/footers scot Word 3 05-22-2015 09:45 AM
Converting the headers & footers into body Headers and Footers Kingsmoss Word 3 04-28-2014 02:43 PM
Converting the headers & footers into body Odd and Even Headers/Footers sarineochaos Word 1 02-04-2014 06:15 PM
Converting the headers & footers into body Headers and Footers teza2k06 Word 1 05-14-2013 11:07 AM
Headers and Footers OverAchiever13 Word 1 05-27-2010 01:30 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:12 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft