1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| Option Explicit
Sub SelectionFichier()
Dim FD As FileDialog
Set FD = Application.FileDialog(msoFileDialogFilePicker)
With FD
.InitialFileName = ThisWorkbook.Path
.AllowMultiSelect = False
.Filters.Clear
.Filters.Add "PDF", "*.pdf", 1
.ButtonName = "Ouvrir fichier"
.Title = "Sélectionner un fichier PDF"
End With
If FD.Show = True Then pdf_to_Excel FD.SelectedItems(1)
Set FD = Nothing
End Sub
'--- https://powerspreadsheets.com/pdf-to-excel-vba/
Sub pdf_to_Excel(sFilePathName As String)
Dim wSh As Worksheet
Dim sAdobeReaderPath As String
Dim sShellPathName As String
Set wSh = ActiveWorkbook.Sheets("Test")
sAdobeReaderPath = "C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe"
sShellPathName = sAdobeReaderPath & " """ & sFilePathName & """"
Call Shell(sShellPathName, vbNormalFocus)
Application.Wait Now + TimeValue("0:00:03")
SendKeys "%afl" '--- Alt, Affichage, aFfichage de page, activer le défiLement
SendKeys "^a" '--- sélectionne tout
SendKeys "^c" '--- copie tout
Application.Wait Now + TimeValue("0:00:10")
With wSh
.Range("A1").Select
.PasteSpecial Format:="Texte"
End With
Call Shell("TaskKill /F /IM AcroRd32.exe", vbHide)
End Sub |
Partager