Importer PDF en excel avec VBA

Fermé
lucieaup Messages postés 17 Date d'inscription jeudi 22 novembre 2012 Statut Membre Dernière intervention 8 avril 2020 - 5 avril 2018 à 10:17
cs_Le Pivert Messages postés 7903 Date d'inscription jeudi 13 septembre 2007 Statut Contributeur Dernière intervention 11 mars 2024 - 10 avril 2018 à 17:30
Bonjour,

je cherche à créer un mini outil pour importer des PDF sous fichier Excel. Aujourd'hui je recois des centaines de PDF par semaine des officiels un peu partout en europe et je dois les charger manuellement un à un dans notre ERP (SAP). j'ai un moyen de les rentrer en masse mais il faut que ca vienne d'un ficheir excel.

Je ne peux pas utiliser un convertisseur en ligne car nous ne sommes pas administrateurs de nos machines et que j'ai affaire à 12 pays en europe, tous n'ont pas les même accés, c'est pourquoi je veux le coder moi même en VBA.


J'ai trouvé ce code en fouinant sur le WEB mais ca ne marche pas sur mon fichier..


'In order to use the macro you must enable the Acrobat library from VBA editor:
'Go to Tools -> References -> Adobe Acrobat xx.0 Type Library, where xx depends
'on your Acrobat Professional version (i.e. 9.0 or 10.0) you have installed to your PC.

'Alternatively you can find it Tools -> References -> Browse and check for the path
'C:\Program Files\Adobe\Acrobat xx.0\Acrobat\acrobat.tlb
'where xx is your Acrobat version (i.e. 9.0 or 10.0 etc.).

Dim PDFApp As AcroApp
Dim PDFDoc As AcroAVDoc
Dim PDFPageView As AcroAvPageView
Dim PDFPath As String
Dim DisplayPage As Integer

'Change this to your own complete PDF path
'Full path example
'PDFPath = "C:\Program Files\Autodesk\ACADM 2010\Setup\en-US\SetupRes\Docs\Acad_Mech_2010_UserGuide.pdf"
'For Word
'PDFPath = ThisDocument.Path & "\" & "PDF Sample.pdf"
'For Power Point
'PDFPath = ActivePresentation.Path & "\" & "PDF Sample.pdf"
'For Excel
PDFPath = ThisWorkbook.Path & "\" & "PDF Sample.pdf"

'Set the page you want to be displayed
DisplayPage = 3

'Initialize Acrobat by creating App object
Set PDFApp = CreateObject("AcroExch.App")

'Set AVDoc object
Set PDFDoc = CreateObject("AcroExch.AVDoc")

'Open the PDF
If PDFDoc.Open(PDFPath, "") = True Then
PDFDoc.BringToFront

'Maximize the document
Call PDFDoc.Maximize(True)

Set PDFPageView = PDFDoc.GetAVPageView()

'Go to the desired page
'The first page is 0
Call PDFPageView.GoTo(DisplayPage - 1)

'-------------
'ZOOM options
'-------------
'0 = AVZoomNoVary
'1 = AVZoomFitPage
'2 = AVZoomFitWidth
'3 = AVZoomFitHeight
'4 = AVZoomFitVisibleWidth
'5 = AVZoomPreferred

'Set the page view of the pdf
Call PDFPageView.ZoomTo(2, 50)

End If

Set PDFApp = Nothing
Set PDFDoc = Nothing

On Error Resume Next

'Show the adobe application
PDFApp.Show

'Set the focus to adobe acrobat pro
AppActivate "Adobe Acrobat Pro"

End Sub

Est ce que quelqu'un pourrait m'aider ?

Merci


A voir également:

2 réponses

cs_Le Pivert Messages postés 7903 Date d'inscription jeudi 13 septembre 2007 Statut Contributeur Dernière intervention 11 mars 2024 729
Modifié le 5 avril 2018 à 15:23
Bonjour,

voir ceci:

https://groups.google.com/forum/?fromgroups#!topic/excelvbamacros/hPZsy2QyFGM

Pour que cela fonctionne il faut mettre cette partie dans un module à part et ensuite suivre les indications pour changer le chemin de l'exe :

' change the path of adobe program as per your desktop
task = Shell("C:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32.exe "

Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) _
As Long

Public Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess _
As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long

Public Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As _
Long, ByVal uExitCode As Long) As Long

Public Const SYNCHRONIZE = &H100000
Public Const STANDARD_RIGHTS_REQUIRED = &HF0000



1
lucieaup Messages postés 17 Date d'inscription jeudi 22 novembre 2012 Statut Membre Dernière intervention 8 avril 2020
5 avril 2018 à 16:11
Merci, mais aparement je n'ai que adobe gratuit et donc ca ne peut fonctionner...
0
cs_Le Pivert Messages postés 7903 Date d'inscription jeudi 13 septembre 2007 Statut Contributeur Dernière intervention 11 mars 2024 729
5 avril 2018 à 17:42
Je l'ai fait fonctionner avec Adobe gratuit!
0
Patrice33740 Messages postés 8556 Date d'inscription dimanche 13 juin 2010 Statut Membre Dernière intervention 2 mars 2023 1 778 > lucieaup Messages postés 17 Date d'inscription jeudi 22 novembre 2012 Statut Membre Dernière intervention 8 avril 2020
5 avril 2018 à 17:45
Apparemment ça fonctionne avec le reader (gratuit) : un copier/coller automatique
0
cs_Le Pivert Messages postés 7903 Date d'inscription jeudi 13 septembre 2007 Statut Contributeur Dernière intervention 11 mars 2024 729
5 avril 2018 à 18:14
Voila un exemple à dezipper:

https://www.cjoint.com/c/HDfqmIgJSLQ

mais comme le dit Patrice33740, il s'agit d'un copier coller. Voir si cela convient!

@+
0
Bonjour,

Merci beaucoup mais ca ne marche pas, je ne comprends pas pourquoi. Qaund je cherche adobe dans mon PC je ne trouve que le raccourci est-ce pour ca?

Voila le type de fichier que je veux mettre sur excel

https://www.cjoint.com/c/HDgis1FnWm6

Merci
0
Patrice33740 Messages postés 8556 Date d'inscription dimanche 13 juin 2010 Statut Membre Dernière intervention 2 mars 2023 1 778
5 avril 2018 à 10:22
Bonjour,

« mais ca ne marche pas sur mon fichier. » As-tu Adobe Acrobat Pro ???
0
lucieaup Messages postés 17 Date d'inscription jeudi 22 novembre 2012 Statut Membre Dernière intervention 8 avril 2020
5 avril 2018 à 11:22
Bonjour, je pense oui j'ai adobe reader XI
0
Patrice33740 Messages postés 8556 Date d'inscription dimanche 13 juin 2010 Statut Membre Dernière intervention 2 mars 2023 1 778
5 avril 2018 à 12:40
Donc tu n'as pas Acrobat (payant), juste un reader (gratuit) !
C'est pour ça que ça marche pas.
0
lucieaup Messages postés 17 Date d'inscription jeudi 22 novembre 2012 Statut Membre Dernière intervention 8 avril 2020
5 avril 2018 à 13:34
ha d'accord, je ne savais pas. Vous connaissez un autre moyen de coder?
0