Computer Hope

Software => Computer programming => Topic started by: cincyshirm61 on June 20, 2013, 01:14:32 PM

Title: vba macro to strip metadata from pdf files
Post by: cincyshirm61 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!
Title: Re: vba macro to strip metadata from pdf files
Post by: cincyshirm61 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!
Title: Re: vba macro to strip metadata from pdf files
Post by: Sidewinder 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 (http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/tsleft.web+Tutorials/OLE~TUTORIAL+WINBATCH~OLE~PROGRAMMING~-~Part~1.txt)  Do a search for Winbatch Articles

Happy Days  8)
Title: Re: vba macro to strip metadata from pdf files
Post by: cincyshirm61 on June 26, 2013, 06:16:02 AM
Once again Sidewinder, you're the best!  Thank you! 
Title: Re: vba macro to strip metadata from pdf files
Post by: bhampl 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.