Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: vba macro to strip metadata from pdf files  (Read 16233 times)

0 Members and 1 Guest are viewing this topic.

cincyshirm61

    Topic Starter


    Rookie

    • Yes
  • Computer: Specs
  • Experience: Experienced
  • OS: Windows 7
vba macro to strip metadata from pdf files
« on: June 20, 2013, 01:14:32 PM »
Hi,

I am looking to write an excel macro that will erase the metadata fields (specifically the "Title" field) from pdf documents.  I want to paste a list of the full pathnames of multiple pdfs in column a, then run a macro to perform this operation. 

Thanks in advance for the help!

cincyshirm61

    Topic Starter


    Rookie

    • Yes
  • Computer: Specs
  • Experience: Experienced
  • OS: Windows 7
Re: vba macro to strip metadata from pdf files
« Reply #1 on: June 24, 2013, 07:59:55 AM »
Maybe this will help.  A former coworker wrote a small macro where you would import the full pathnames into column A, run the below macro, and it would add the full filepath to the "Keywords" line in the pdf metadata.  This was very helpful when trying to trace extracted pdf pages back to its original file. 

Code: [Select]
Sub BrandBreakouts()
Dim PDF As CAcroPDDoc
Dim RawSet As Range
Range("A1").Select
Range(Selection, Selection.End(xlDown)).Select
Set RawSet = Selection
Set PDF = CreateObject("AcroExch.PDDoc")
For Each pth In RawSet
    If PDF.Open(pth) = -1 Then
        st1 = PDF.SetInfo("Keywords", pth)
        st2 = PDF.Save(PDSaveCollectGarbage, pth)
        PDF.Close
    End If
Next pth
       
End Sub

I just want to clear the title field, rather than add anything. Thanks again!

Sidewinder



    Guru

    Thanked: 124
  • Experience: Familiar
  • OS: Windows 10
Re: vba macro to strip metadata from pdf files
« Reply #2 on: June 25, 2013, 01:40:36 PM »
Would have thought finding info about Acrobat objects would have been simple. Guess again!

Code: [Select]
st1 = PDF.SetInfo("Title", "")

If VBA has a constant literal for nulls use that instead of ""

Citation  Do a search for Winbatch Articles

Happy Days  8)
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

cincyshirm61

    Topic Starter


    Rookie

    • Yes
  • Computer: Specs
  • Experience: Experienced
  • OS: Windows 7
Re: vba macro to strip metadata from pdf files
« Reply #3 on: June 26, 2013, 06:16:02 AM »
Once again Sidewinder, you're the best!  Thank you! 

bhampl



    Newbie

    • Experience: Familiar
    • OS: Windows 10
    Re: vba macro to strip metadata from pdf files
    « Reply #4 on: February 16, 2018, 07:20:16 AM »
    Hallo!
    When I began to step in your Subroutine in my MS VBA 7 in MS Excel 2010 I received error "User-defined type not defined" on declaration "Dim PDF As CAcroPDDoc". Is there missing any library in VBA?
    In my VBA for Excel, I need to get property "Title" from "PDF information" sheet from PDF file located on my computer.
    Thanks.