Importar PDF a Excel con VBA
lucieaup
Mensajes publicados
18
Estado
Miembro
-
cs_Le Pivert Mensajes publicados 8437 Estado Colaborador -
cs_Le Pivert Mensajes publicados 8437 Estado Colaborador -
Hola,
estoy buscando crear una mini herramienta para importar PDFs a un archivo Excel. Hoy recibo cientos de PDFs por semana de oficinas oficiales de toda Europa y tengo que cargarlos manualmente uno por uno en nuestro ERP (SAP). Tengo una forma de ingresarlos en masa, pero debe venir de un fichero Excel.
No puedo usar un convertidor en línea porque no somos administradores de nuestras máquinas y tengo que trabajar con 12 países en Europa; no todos tienen el mismo acceso, por lo que quiero programarlo yo mismo en VBA.
Encontré este código buscando en la WEB, pero no funciona con mi archivo..
'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
Configuration: Windows / Internet Explorer 11.0
estoy buscando crear una mini herramienta para importar PDFs a un archivo Excel. Hoy recibo cientos de PDFs por semana de oficinas oficiales de toda Europa y tengo que cargarlos manualmente uno por uno en nuestro ERP (SAP). Tengo una forma de ingresarlos en masa, pero debe venir de un fichero Excel.
No puedo usar un convertidor en línea porque no somos administradores de nuestras máquinas y tengo que trabajar con 12 países en Europa; no todos tienen el mismo acceso, por lo que quiero programarlo yo mismo en VBA.
Encontré este código buscando en la WEB, pero no funciona con mi archivo..
'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
Configuration: Windows / Internet Explorer 11.0
2 respuestas
-
Hola,
ver esto:
https://groups.google.com/forum/?fromgroups#!topic/excelvbamacros/hPZsy2QyFGM
Para que funcione hay que colocar esta parte en un módulo aparte y luego seguir las indicaciones para cambiar la ruta del exe :
' cambia la ruta del programa de adobe según tu escritorio
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
-
Hola,
« pero eso no funciona en mi archivo. » ¿Tienes Adobe Acrobat Pro ???
--
Cordialmente
Patrice