Vba: Pdf aus Excel befüllen Focus derExcel-Datei
19.07.2014 12:05:05
Frank J. Müller
Hallo,
ich versuche Formulare aus Pdf-Dateien zu befüllen.
Ausgangspunkt ist dieses Script https://forums.adobe.com/thread/302309
Aber es scheint nicht zu funktionieren an der Stelle wo er versucht zum zweiten mal auf die Zellen zugreifen will.
Es kommt ein Automatisierungsfehler. Scheinbar erhält das Excel-Fenster nicht wieder den Fokus.
Hat jemand einen Tipp?
Vielen Dank!
Hier die Datei:
https://www.herber.de/bbs/user/91588.zip
Sub Pdfdings()
Dim gApp As Acrobat.CAcroApp
Dim avdoc As Acrobat.CAcroAVDoc
Dim gPDDoc As Acrobat.CAcroPDDoc
Dim DOC_FOLDER As String
Dim x As Boolean
Dim mydoc As Workbook
Set gApp = CreateObject("AcroExch.App")
Set gPDDoc = CreateObject("AcroExch.PDDoc")
Set avdoc = CreateObject("AcroExch.AVDoc")
Set mydoc = ThisWorkbook
'MsgBox Sheets("Tabelle4").Cells(1, 2).Value
DOC_FOLDER = Sheets("Tabelle4").Cells(1, 2).Value
'Hides Acrobat - So Far So Good
'gApp.Hide
Dim FormApp As AFORMAUTLib.AFormApp
Dim AcroForm As AFORMAUTLib.Fields
Dim Field As AFORMAUTLib.Field
Dim z, i, j, n As Integer
Dim wksTab1 As Worksheet
Dim Feld, Inhalt As String
Set wksTab1 = ThisWorkbook.Sheets("Tabelle2")
'Open PDF that I choose. Acrobat still has not flashed on my screen
j = 2
i = 2
While i < 3
x = avdoc.Open(DOC_FOLDER & "formular_ve01a.pdf", "temp")
'Acrobat Now Pops up on my screen. However, I get an error without this line. avdoc.Show works _
_
the same as Maximize it seems.
avdoc.Maximize (1)
'Hides it again, right after it opens. This creates a flash
'gApp.Hide
Set FormApp = CreateObject("AFormAut.App")
While j < 39
'If the Maximize line is not there, this is where I receive error about document viewer
Feld = mydoc.Sheets("Tabelle2").Cells(1, j).Value
Inhalt = mydoc.Sheets("Tabelle2").Cells(i, j).Value
'If j > 2 Then MsgBox Feld
'MsgBox Inhalt
For Each Field In FormApp.Fields
If Field.Name = Feld Then
Field.Value = Inhalt
End If
Next
j = j + 1
Wend
Dim sDoc
Set sDoc = avdoc.GetPDDoc
saveOk = sDoc.Save(1, DOC_FOLDER & "OK_Formular" & wksTab1.Cells(1, 1).Value & ".pdf")
avdoc.Close (1)
gApp.Exit
i = i + 1
Wend
End Sub