Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1164to1168
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Inhaltsverzeichnis

VBA in PDF

VBA in PDF
PeTeR
Hallo VBA-Freaks,
ich würde gerne folgenden Prozess programmieren:
1) Excel-Daten als xml speichern
2) Pdf-Vorlage öffnen und Daten aus 1) in Vorlage importieren
3) Pdf speichern
Kann man überhaupt pdf aus Excel "fernsteuern"? Gibt es dafür eine Objektbibliothek und einen entsprechenden Verweis?
Vielen Dank für eure Hilfe!!!
PeTeR

4
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Benutzer
Anzeige
AW: VBA in PDF
12.07.2010 11:27:07
Ramses
Hallo
"...1) Excel-Daten als xml speichern .."
Datei - Speichern Unter- XML-Format.
Sollte also kein Problem sein
"...2) Pdf-Vorlage öffnen und Daten aus 1) in Vorlage importieren..."
Warum schreibst du die Daten nicht gleich aus der XLS in die PDF Datei ?
Wozu der Umweg über die XML
"...3) Pdf speichern..."
Welches PDF ?
Es gibt zig-verschiedene Varianten von PDF Generatore, aber nicht alle unterstützen zuverlässig die Formularfelder, einige gar nicht.
Mit dem PDF Generator von Office geht das aber überhaupt nicht. Dazu brauchst du ein PDF Programm, das eben diese Funktionen unterstützt und dann "ferngesteuert" werden muss als Object.
Vorzugsweise Adobe PDF. Damit werden die Formularfelder nach meiner Erfahrung am Besten und sichersten ausgefüllt.
"...Kann man überhaupt pdf aus Excel "fernsteuern"? .."
Ja
"...Gibt es dafür eine Objektbibliothek und einen entsprechenden Verweis..."
Ja, aber nur wenn du ein entsprechendes PDF Programm installiert hast.
Am Besten googelst du mal nach VBA, Excel und PDF oder schaust mal in den einschlägigen Addobe Foren vorbei.
Gruss Rainer
Anzeige
AW: VBA in PDF
12.07.2010 15:07:47
PeTeR
Hallo Ramses,
schön, wieder von dir zu hören und ganz herzlichen Dank für deine Antwort.
Ich finde in den Verweisen: Adobe Acrobat 8.0 Type Library
Kann ich damit den Adobe Acrobat "fernsteuern"?
Wie könne ich Daten aus xlsx direkt in eine PDF-Vorlage schreiben?
Vielen Dank für deine Hilfe
PeTeR
AW: VBA in PDF
12.07.2010 22:08:13
Ramses
Hallo
Das ist ein Beispiel aus meinem Fundus.
Benutzt oder getestet habe ich das aber auch noch nicht, weil ich das noch nicht brauchte
Sub InsertFormCaptures()
    '---------------------- Start module ------
    'I Get It! Development provides programming examples
    'for illustration only, without warranty either
    'expressed or implied, including, but not limited to,
    'the implied warranties of merchantability and/or
    'fitness for a particular purpose. This article
    'assumes that you are familiar with the programming
    'language being demonstrated and the tools used to
    'create and debug procedures. These examples assume that
    'you have licensed copies of all relevant software installed
    'on the machine upon which the examples will be run.
    
    'This routine takes preexisting .jpg files (Run CreateScreenShots first)
    'and adds them to a preexisting CodeFile.pdf file (print to PDF from VB Editor)
    'The routine assumes that all files are in C:\Documentation. Please
    'change this in the following code or create the folder.
    'Remember to set a reference to Adobe Acrobat Type Library in
    'Tools > References in the VB Editor
    '------ Written by Theo Callahan 4/2003 -------------
    
    Const DOC_FOLDER As String = "C:\Documentation"
    
    Dim objCurrent As AccessObject
    Dim frmCurrent As Form
    Dim strFormName As String
    Dim blnNeedToClose As Boolean
    
    Dim Acroapp As CAcroApp
    Dim avCodeFile As CAcroAVDoc
    Dim avFormCapture As CAcroAVDoc
    Dim pdCodeFile As CAcroPDDoc
    Dim pdFormCapture As CAcroPDDoc
    Dim lngPage As Long
    Dim AVPage As CAcroAVPageView
    Dim PDPage As CAcroPDPage
    
    'Start Acrobat in the background
    Set Acroapp = CreateObject("AcroExch.App")
    
    'Uncomment the following line if you want to watch the program run
    Acroapp.Show
    
    Set avCodeFile = CreateObject("AcroExch.AVDoc") 'This is the code file
    Set avFormCapture = CreateObject("AcroExch.AVDoc") 'This will be each jpg in turn
    
    'Open the already created code file
    avCodeFile.Open DOC_FOLDER & "\CodeFile.pdf", "Code File"
    Set pdCodeFile = avCodeFile.GetPDDoc
    
    'Loop through each form. We have to use the AllForms collection because Forms
    'only shows open forms. In order to document all of them, we loop through
    'the AllForms collection and open forms as needed. They have to be open for
    'us to check whether or not they have modules(associated code)
    
    For Each objCurrent In CurrentProject.AllForms
    
        'Open the form if it's not already open
        If Not objCurrent.IsLoaded Then
            blnNeedToClose = True 'This reminds us to close the form when done
            DoCmd.OpenForm objCurrent.name, acDesign, , , acFormPropertySettings, acWindowNormal
            Set frmCurrent = Application.Screen.ActiveForm
            strFormName = frmCurrent.name
        Else
            blnNeedToClose = False
            Set frmCurrent = Forms(objCurrent.name)
            strFormName = frmCurrent.name
        End If
    
        'Open the jpg file
        avFormCapture.Open DOC_FOLDER & "\" & strFormName & ".jpg", ""
        Set pdFormCapture = avFormCapture.GetPDDoc
    
        If frmCurrent.HasModule Then 'if there's code, look for the right spot
    
        'Look for the form name and ' - 1' in the code file: that's page 1 of code
        avCodeFile.FindText "Form_" & strFormName & " - 1", 0, 0, 1
        Set AVPage = avCodeFile.GetAVPageView
    
        'Go to the page just before the form's code
        lngPage = AVPage.GetPageNum - 1 'we want page before
        If lngPage < 0 Then lngPage = 0
    
    Else
        'If there's no code, throw the form in the back of the package
        lngPage = pdCodeFile.getnumpages - 1
    End If
    
    'Insert the jpg at the right page
    pdCodeFile.InsertPages lngPage, pdFormCapture, 0, 1, 0
    
    'Unfortunately, there is no page 0 so the first form comes AFTER the first
    'page of code if it's on page 1. We need to swap the image and code if that's the
    'case
    If lngPage = 0 Then pdCodeFile.MovePage 1, 0
    
    'Close the jpg file
    pdFormCapture.Close
    avFormCapture.Close 1
    Set pdFormCapture = Nothing
    
    'If we need to, close the form
    If blnNeedToClose Then DoCmd.Close acForm, strFormName, acSaveNo
    
    Next objCurrent
    
    'close the doc file now with form captures
    pdCodeFile.Close
    avCodeFile.Close 0
    
    'Exit Acrobat
    Acroapp.Exit
    Set objCurrent = Nothing
    Set frmCurrent = Nothing
    Set Acroapp = Nothing
    Set avCodeFile = Nothing
    Set pdCodeFile = Nothing
    Set avFormCapture = Nothing
End Sub

Aber es soll Dir mal als Ansatz dienen, wie so was geht.
Den PDF-Link habe ich noch,... als Ansatz ist das nicht schlecht
http://www.adobe.com/devnet/acrobat/pdfs/VBJavaScript.pdf
Gruss Rainer
Anzeige
AW: VBA in PDF
13.07.2010 08:42:32
PeTeR
Hallo Ramses,
vielen Dank für das Bespiel und die PDF-Datei! Damit bin ich erst einmal die nächsten Tage beschäftigt ;-)
Gruß
PeTeR

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige