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