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:
Dear Sir @Fennek,

its seem while opening pdf in word, word converted pdf file in image so there are no scope to find any char in opened pdf file in word which's content in transformed in image by word.

i have another Java based free application "DocFetcher" that create any files content index and search result file. if we can get this file's list in excel we can delete it. Or can we use that index files directly to sear in within & track that file name to delete?
what is your opinion?

can there are way to get this file's list in excel to process?

Regards,

Chirag Raval
 
Last edited:
Upvote 0

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Hi,

my test-scenarios was:

Create a new Word Document:

Code:
Sub F_en()
'type in:  =lorem(5, 12)
'confirm with "Return"

ActiveDocument.ExportAsFixedFormat "c:\temp\pdf.pdf", wdExportFormatPDF, False

Set Wd = Documents.Open("c:\temp\pdf.pdf")

'one-time: deactive alert-message

End Sub

I inserted by hand your search-string and save it in a folder with 2-3 other pdf.

In this case my code worked: (when enable the Kill-command)

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)
If GetAttr(Pf & f) = vbNormal Then

    Set Doc = Documents.Open(Pf & f)
        With Doc.Content.Find
            .Execute SWd, True, True, falsw
            If .Found Then
                Debug.Print f
        'kill Pf & f
            Else
                SetAttr Pf & f, vbReadOnly
            End If
        End With
    Doc.Close 0
endif

f = Dir
Loop
beep
End Sub

If your process to create the pdf uses not the text, but a picture of the text, I have no idea, how to seach.

regards
 
Upvote 0
Dear Sir @Fennek,

my first test of your post no 10, there ar not shown any PDF files in that folder though there are many.
see the attached screen shot for that, in file picker dilog , seem we must mention file type in that dialog box to select the files.

nvr0qa.png
[/IMG]

also i can not under stand your this earlier code its just create currently open word doc as pdf., its related to your post no 10?
please help.

Regards,

Chirag Raval
 
Upvote 0
Hi, in my code there is a FOLDER-picker, not a file-picker! In the window you move to the folder, select it and confirm with the OK-button. Then the code will go through all pdf-files. PLEASE test it in a folder with 2-10 pdf-files, at least one including the search-word. regards
 
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

Just PDF opening in Word process , word convert PDF file's all text in image.

I am using Word 2016 64 bit, Os wind-17 64 bit.

screen shot attached
m9x84l.png
[/IMG]

Please help

Regards,

Chirag Raval
 
Last edited:
Upvote 0
where is the problem? Just click "never show again" (not handy for 100,000 files) and the ok-button.
 
Upvote 0
Upvote 0
Hi, MS Word opens this pdf as one picture and CANNOT search for specific word. BUT Libre Office Writer and Firefox open the pdf AND CAN search for words. Mayby my code runs in LO as well (first line in module: option vbasupport 1) Maybe you need a professional. regards
 
Upvote 0
Hi,

I tried to use the MS InternetExplorer:

- manually it worked
- controlled by VBA there was an error

Code:
Sub IE()

Dim IE As Object
Dim oHTML As Object

URL = "z:\Folder\RL Commercial Invoice No. 13195282.pdf"
Debug.Print Dir(URL)

Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True

IE.navigate URL

While IE.busy Or IE.readyState <> READYSTATE_COMPLETE
    DoEvents
Wend

'Set                    ' tied as well
oHTML = IE.Document.all '<<<<<<<<<<<< Error >>>>>>>>>>>>>>
    ' ie.document.FindText "Search string"
    Debug.Print c00
c00 = IE.Document.body.innerhtml
    
    Debug.Print c00
    
IE.Quit
Set IE = Nothing
End Sub

The keyword "Document" was not accepted, although all tutorials use it.

Hopefully one expert here can point out the issue.

regards
 
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,270
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