0

I have a PDF file that I am trying to parse text out of. I opened the file using Microsoft Word, and text I need is in the header. On the first page, the header is justified left with a center tab that has the text (plain English name document title instead of the complicated reference name) that I am trying to grab. There is a right tab that has a page number control that I don't care about.

When I try to run the following:

Debug.Print ThisDocument.Sections(1).Headers(wdHeaderFooterPrimary).Exists

it gives me True, so I know the header exists. However, when I try to run

Debug.Print ThisDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range.Text

it gives me nothing but an empty string, which I can further confirm by wrapping it in a Len(…) command which gives me 1. How can I get the text out of the header?

Of note, I tried using some Adobe SDK functions which would have been easier, but I do not have the professional Acrobat suite so I do not have access to those tools. Hence the MS Word workaround.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
SandPiper
  • 2,816
  • 5
  • 30
  • 52
  • Most likely your pdf is not appropriately tagged and MS Word cannot recognize as headers what you consider to be header material. – mkl Jul 29 '18 at 14:37
  • 1
    `ThisDocument` refers exclusively to the file in which the macro is contained. That's unlikely to be the PDF file, which you want to address. Use `ActiveDocument` instead and see if that helps. If not, please tell us which VERSION of Word you're using. – Cindy Meister Jul 29 '18 at 15:20
  • @CindyMeister, that did it, thank you! If you put that into an official answer I'll mark it as accepted. I appreciate the help! – SandPiper Jul 29 '18 at 22:54
  • Possible duplicate of [store word content in variable vba](https://stackoverflow.com/questions/49581503/store-word-content-in-variable-vba) – Cindy Meister Jul 30 '18 at 15:23
  • I'd like to take some credit :-), but this is a common problem so I've marked it as a "duplicate" where there's already a fuller explanation about the two objects. – Cindy Meister Jul 30 '18 at 15:25
  • Take the credit, you have the accepted answer at that link anyway ;) – SandPiper Jul 31 '18 at 12:49

0 Answers0