Hello dear fellow VBA WIzards!
I am currently working on a project that has a lot of PDF-files that need to be read and some data copied.
I don't have access to the full Adobe suite, so I can't use the reference-relying codes I've found here and on the www.
I currently have a working program, but there is one awfully inconvenient thing that is making me a bit mad.
The code goes through a selected folder, finds all the PDF-files in it, copies the content to an Excel sheet, then finds the values I am looking for and copies them
to another Excel sheet.
So far so good. Only problem, before opening the PDF's, I get a warning about opening hyperlinks...That means I still need to sit here and click every time.
I tried sending SendKeys, but to no avail.
Is there a way to copy data from PDF without opening it? Or a way to bypass this warning message(without making changes to the register/keys)?
With maybe a sendkey-like command that is accepted by this warning-message?
I will add my code. Don't get mad about my coding skills, I am still 'new' and don't know much about coding ethics.. I just figure things out by trial and error, and copying found code..
I am open to any suggestion, about my problem or my code in general.
Thank you in advance!
And if this question has been posted somewhere else, please let me know! I tried tolook for a similar question, but didn't find anything really fitting..
Kind regards,
I am currently working on a project that has a lot of PDF-files that need to be read and some data copied.
I don't have access to the full Adobe suite, so I can't use the reference-relying codes I've found here and on the www.
I currently have a working program, but there is one awfully inconvenient thing that is making me a bit mad.
The code goes through a selected folder, finds all the PDF-files in it, copies the content to an Excel sheet, then finds the values I am looking for and copies them
to another Excel sheet.
So far so good. Only problem, before opening the PDF's, I get a warning about opening hyperlinks...That means I still need to sit here and click every time.
I tried sending SendKeys, but to no avail.
Is there a way to copy data from PDF without opening it? Or a way to bypass this warning message(without making changes to the register/keys)?
With maybe a sendkey-like command that is accepted by this warning-message?
I will add my code. Don't get mad about my coding skills, I am still 'new' and don't know much about coding ethics.. I just figure things out by trial and error, and copying found code..
I am open to any suggestion, about my problem or my code in general.
Thank you in advance!
And if this question has been posted somewhere else, please let me know! I tried tolook for a similar question, but didn't find anything really fitting..
Kind regards,
VBA Code:
Sub OpenPDFInFolder()
'Variable Declaration
Dim sFilePath As String
Dim sFileName As String
Dim ws As Worksheet
Dim PDF_path, PDF_P As String
Dim Kolom As String
Dim inputFileDialog As FileDialog
Dim folderChosenPath As Variant
Dim Mol As Range
Dim cell As Range
Dim Mw As String
Dim strAddress As String
Dim Mols As String
Dim Eind As Range
Dim Laatst As Variant
Dim Rij As String
Dim i As Integer
Dim Molss As Range
Dim Final As String
Set inputFileDialog = Application.FileDialog(msoFileDialogFolderPicker)
With inputFileDialog
.Title = "Select Folder to Start with"
.AllowMultiSelect = True
If .Show = False Then Exit Sub
folderChosenPath = .SelectedItems(1)
End With
Rij = 5
PDF_path = folderChosenPath
'Check for back slash
If Right(PDF_path, 1) <> "\" Then
PDF_path = PDF_path & "\"
End If
sFileName = Dir(PDF_path & "*.pdf")
Do While Len(sFileName) > 0
'Display file name in immediate window
'MsgBox (sFileName)
Final = PDF_path & sFileName
Debug.Print sFileName
Debug.Print PDF_path
Debug.Print Final
Kolom = "A"
'open the pdf file
ActiveWorkbook.FollowHyperlink Final
SendKeys "y", True
SendKeys "^a^c", True
'SendKeys "^a", True
'SendKeys "^c", True
SendKeys "{NUMLOCK}", True
Call Shell("TaskKill /F /IM AcroRd32.exe", vbHide)
Application.ScreenUpdating = True
Set ws = ThisWorkbook.Sheets("Sheet1")
ws.Activate
ws.Range("A:A").ClearContents
ws.Range(Kolom & 1).ClearContents
ws.Range(Kolom & 1).Select
ws.Paste
'SendKeys "^v", True
'ws.Activate
'ws.Range("A1").ClearContents
'ws.Range("A1").Select
'ws.Paste
'SendKeys "^v", True
Application.ScreenUpdating = True
Set cell = Range("A:A").Find("> 4297317")
If cell Is Nothing Then
MsgBox ("Not found")
Else
MsgBox (cell.Address)
End If
Mx = cell.Address
Mw = Right(Mx, 2)
Ms = Mw + 2
Mols = Range(Kolom & Ms)
MsgBox (Mols)
Range("C5:C5").Activate
Cells(1, 6) = Mols
Set Eind = Range("A:A").End(xlDown)
' MsgBox (Eind)
Laatst = Split(Eind)
Set wss = ThisWorkbook.Sheets("MW average and fractions")
'MsgBox (Laatst(1))
wss.Activate
wss.Range("C" & Rij).Select
Range("C" & Rij) = Mols / 1000
wss.Range("D" & Rij).Select
Range("D" & Rij) = Laatst(1)
wss.Range("E" & Rij).Select
Range("E" & Rij) = Laatst(2)
wss.Range("F" & Rij).Select
Range("F" & Rij) = Laatst(3)
wss.Range("G" & Rij).Select
Range("G" & Rij) = Laatst(4)
wss.Range("H" & Rij).Select
Range("H" & Rij) = Laatst(5)
'Set the fileName to the next available file
sFileName = Dir
Rij = Rij + 1
Loop
End Sub
Last edited by a moderator: