Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-27-2017, 02:10 AM
puff puff is offline Obtain contents from headers/footers and insert them Windows 7 64bit Obtain contents from headers/footers and insert them Office 2013
Advanced Beginner
Obtain contents from headers/footers and insert them
 
Join Date: Apr 2017
Posts: 60
puff is on a distinguished road
Question Obtain contents from headers/footers and insert them

Hi all! Is it possible for VBA to extract the contents from every page's header and footer and then insert them to the first and the last line of that page respectively? I used Acrobat to convert a PDF (actually, a PPT in PDF format) into word, but some pages' headings turn into headers for pages in Word and they're all different.

I cannot use the export function of powerpoint to avoid this issue since I don't have the original PPT file. Additionally, I can't let Acrobat export the text into the plain text because it lost Greek letters in the original PDF.

I searched a lot, but most examples only add content into headers, not the opposite direction. Additionally, if VBA can do this, one major problem might be that adding contents from headers/footers changes how the contents arrange on every page--contents will move backward and get onto latter pages.



Could someone help me out on this? I also appreciate any other better ideas on extracting PDF text.
Reply With Quote
  #2  
Old 12-27-2017, 02:53 AM
gmayor's Avatar
gmayor gmayor is offline Obtain contents from headers/footers and insert them Windows 10 Obtain contents from headers/footers and insert them Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,105
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Headers and footers are constituent parts of Sections rather than Pages and there are potentially three headers and three footers for each section. Undoubtedly if there is more information added than will fit on the page, then text flow will cause the text to create new pages within the sections. Without access to the document, it will inevitably be a tad hit or miss, but the following should be close, given the nature of the document - however process a copy of the document! :

Code:
Sub Macro2()
Dim oSection As Section
Dim oHeader As Range
Dim oFooter As Range
Dim oRng As Range
Dim i As Integer
    For i = 1 To ActiveDocument.Sections.Count
        Set oSection = ActiveDocument.Sections(i)
        Set oHeader = oSection.Headers(wdHeaderFooterPrimary).Range
        oHeader.End = oHeader.End - 1
        Set oFooter = oSection.Footers(wdHeaderFooterPrimary).Range
        oFooter.End = oFooter.End - 1
        Set oRng = oSection.Range
        oRng.Collapse 1
        oRng.Text = oHeader.Text & vbCr
        Set oRng = oSection.Range
        oRng.End = oRng.End - 1
        oRng.Collapse 0
        oRng.Text = vbCr & oFooter.Text
        oSection.Headers(wdHeaderFooterPrimary).Range.Delete
        oSection.Footers(wdHeaderFooterPrimary).Range.Delete
    Next i
lbl_Exit:
    Set oRng = Nothing
    Set oFooter = Nothing
    Set oHeader = Nothing
    Set oSection = Nothing
    Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 12-31-2017, 03:05 AM
slaycock slaycock is offline Obtain contents from headers/footers and insert them Windows 7 64bit Obtain contents from headers/footers and insert them Office 2016
Expert
 
Join Date: Sep 2013
Posts: 256
slaycock is on a distinguished road
Default

Have you tried importing the pdf into Powerpoint rather than Word?
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to insert page break when copying Excel table into PP? How set headers/footers in PP like Word? proja PowerPoint 0 09-16-2015 12:36 PM
Obtain contents from headers/footers and insert them Headers and Footers Kingsmoss Word 3 04-28-2014 02:43 PM
Obtain contents from headers/footers and insert them Odd and Even Headers/Footers sarineochaos Word 1 02-04-2014 06:15 PM
Obtain contents from headers/footers and insert them 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 06:20 PM.


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