How to delete PDF files in perticular folder ,files, which's body/ content contain/have some specific words?

chirag050675

Board Regular
Joined
Sep 3, 2016
Messages
69
Dear All Experts,

I already search for code on web but all codes construct & delete files based on search for specific character in file name & extensions.

But my requirement of VBA code to delete all .PDF file not on based of file name but file's body/content have/contain some specific word.

files resides in particular single folder or may be subfolder also.

May be search or find for that word with wild card can help to delete that file if that word found in that file.

Hope there are help available in this great platform & will be appreciated well.

Regards,

Chirag Raval
 
Last edited:

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Dear Sirs @Kenneth Hobson,

I have 1,20,000 .pdf files in folder, mixed.
Daily download .pdf files for whole regions for generated invoices. mail also have transporter's lorry receipts .pdf with it.
but can not determine based on file name that it is invoice (required file) or lorry receipt (LR)(Not required file)
Means, do not provide any clue in file name that we can consider that it is downloadable or not.
Target just want to haver invoice copies in folder.
require to Search - Find in - within every .pdf files for word "Consignee Copy"
If file contain word "consignee copy" then delete that file
obviously I can distribute files with about 10,000 files in one folder to make task easier for target that folder
& after process complete, I can move balanced required file in another folder & transfer next 10,000 files for process.
Just It.

Can Anyone help here? Just Require VBA code?

Regards,

Chirag Raval
 
Upvote 0
Dear All Experts,

If pdf content is selecteble text, (not as scanned image).
VBA can do its job.

Is VBA is only for office application ? & Can't do
Anything on Pdf?

If VBA can do then How?..

I am waiting eagerly..due to files fallen in folder daily in some quantity.
I am be very thankful for this forum's environment and people's
if you can little help.

Regards,

Chirag Raval.
 
Last edited:
Upvote 0
Hello, it is a interesting topic and, unfortunately, no reply. My trials with Excel failed, but MS Word can open PDF directly. No additional software or "createObject" is needed. So a Word-VBA code can search for the target-string and delete the file, if needed. For so many files you will need a long time. regards
 
Upvote 0
Dear Sir @Fennek,

Thank god some one can help me.
you are only one who lighten in the darkness, thank you.
I download file from https://pdfgrep.org/index.html , & i already some study here for its more
https://gitlab.com/pdfgrep/pdfgrep its seems it have tremendous power but use require more knowledge to use it properly
& my bad luck i don't have it.

Can you help for WORD (DOC) VBA that work TO complete this task?

Hope there are some way there.

Again Thanks

Regards,

Chirag Raval
 
Last edited:
Upvote 0
Hi,

it needs MS Word 2013 or later:

Code:
 Const SWd As String = "Consignee Copy"

Sub F_en()
Dim Doc As Document

With Application.FileDialog(msoFileDialogFolderPicker)
    .InitialFileName = "c:\temp"
    If .Show Then Pf = .SelectedItems(1) & "\"
'    Debug.Print Pf
End With

f = Dir(Pf & "*.pdf")

Do While Len(f)
    Set Doc = Documents.Open(Pf & f)
        With Doc.Content.Find
            .Execute SWd, True, True, falsw
            If .Found Then
                Debug.Print f
                SetAttr Pf & f, vbNormal
            Else
                SetAttr Pf & f, vbReadOnly
            End If
        End With
    Doc.Close 0
f = Dir
Loop

End Sub

You can check it, later all files with Attribute "normal" will be deleted, all "ReadOnly" will remain.

Report about the result.

(Of course: no garanties or warentees)

regards
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,898
Messages
6,175,272
Members
452,628
Latest member
dd2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top