Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1128to1132
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

mit PDF Creator ein Tabellenblatt als pdf abspeich | Herbers Excel-Forum

mit PDF Creator ein Tabellenblatt als pdf abspeich
14.01.2010 16:16:29
Horst

Hallo
ich will ein Tabellenblatt als pdf abspeichern.
Dank diesem Forum habe ich einen Code gefunden, welcher jedoch bei mir nicht richtig funktioniert.
Wenn ich bei Break (siehe Code) stoppe, ist der PDFCreator geöffnet, das umzuwandelne Tabellenblatt
ist eingetragen und der Status ist "Drucken".
Weiter passiert jedoch nicht. Bei diversen Versuchen ist es mir schon mal gelungen den Druck in der
PDFCreator Oberfläche zu starten. Das ist zwar nicht Sinn der Sache, aber danach läuft auch der weitere
VBA Code ohne Fehler durch.
Ohne Breakpoint dreht VBA in der letzten Do Loop Schleife Endlosrunden bis es irgenwann mal eine
Fehlermeldung gibt. (z.B. Speicherüberlauf)
Ich meine bei mir zu Hause mit gleicher Softwareumgebung aber langsamerem Rechner hat dieser Code
schon mal funktioniert.
Es wäre super, wenn mir jemand einen Tip geben könnte.
Vielen vielen Dank im Voraus
Gruß Horst

  • 
    Sub PrintToPDF_Early(Blattname)
    'Author       : Ken Puls (www.excelguru.ca)
    'Macro Purpose: Print to PDF file using PDFCreator
    ' (Download from http://sourceforge.net/  _
    _
    projects/pdfcreator/)
    '   Designed for early bind, set reference to PDFCreator
    Dim pdfjob As PDFCreator.clsPDFCreator
    Dim sPDFName As String
    Dim sPDFPath As String
    Dim DefaultPrinter
    '/// Change the output file name here! ///
    sPDFName = "Test.pdf"
    'sPDFPath = ActiveWorkbook.Path & Application.PathSeparator
    sPDFPath = "C:\Temp\Repatest"
    'Check if worksheet is empty and exit if so
    If IsEmpty(Worksheets(Blattname).UsedRange) Then Exit Sub
    Set pdfjob = New PDFCreator.clsPDFCreator
    With pdfjob
    If .cStart("/NoProcessingAtStartup") = False Then
    MsgBox "Can't initialize PDFCreator.", vbCritical + _
    vbOKOnly, "PrtPDFCreator"
    Exit Sub
    End If
    .cOption("UseAutosave") = 1
    .cOption("UseAutosaveDirectory") = 1
    .cOption("AutosaveDirectory") = sPDFPath
    .cOption("AutosaveFilename") = sPDFName
    .cOption("AutosaveFormat") = 0    ' 0 = PDF
    .cClearCache
    .cPrinterStop = False '
    End With
    'Print the document to PDF
    Worksheets(Blattname).PrintOut copies:=1, ActivePrinter:="PDFCreator"
    BreaK
    'Wait until the print job has entered the print queue
    Do Until pdfjob.cCountOfPrintjobs = 1
    DoEvents
    Loop
    pdfjob.cPrinterStop = False
    'Wait until PDF creator is finished then release the objects
    Do Until pdfjob.cCountOfPrintjobs = 0
    DoEvents
    Sleep 250
    Loop
    MsgBox "PDF Dokument wurde erzeugt"
    pdfjob.cClose
    Set pdfjob = Nothing
    End Sub
    


  • 5
    Beiträge zum Forumthread
    Beiträge zu diesem Forumthread

    Betreff
    Datum
    Anwender
    Anzeige
    AW: mit PDF Creator ein Tabellenblatt als pdf abspeich
    14.01.2010 16:35:39
    Horst
    P.S.
    Wenn ich den PDFCreator manuell bediene, also ohne VBA, dann funktioniert alles optimal.
    Gruß Horst
    AW: mit PDF Creator ein Tabellenblatt als pdf abspeich
    14.01.2010 17:00:42
    Luschi
    Hallo Horst,
    laß dir mit dem nachfolgenden Makro doch mal alle am PC installieren Drucker anzeigen.
    Vielleicht hat er einen anderen Namen.
    
    Sub installierteDrucker()
    On Error Resume Next
    Dim lngZeile As Long
    Dim objWMIService As Object, colItems As Object, objItem As Object
    lngZeile = 1
    Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
    Set colItems = objWMIService.ExecQuery("Select * from Win32_Printer", , 48)
    For Each objItem In colItems
    ActiveSheet.Range("A" & lngZeile) = objItem.Caption
    lngZeile = lngZeile + 1
    Next
    Set objWMIService = Nothing
    Set colItems = Nothing
    Set objItem = Nothing
    End Sub
    
    Gruß von Luschi
    aus klein-Paris
    Anzeige
    AW: mit PDF Creator ein Tabellenblatt als pdf abspeich
    15.01.2010 07:14:39
    Horst
    Hallo Luschi,
    vielen Dank, habe Dein Makro ausgeführt und den Namen kontrolliert, der ist o.k.
    Hat vielleicht sonst noch jemand eine Idee??
    Gruß Horst
    AW: mit PDF Creator ein Tabellenblatt als pdf abspeich
    15.01.2010 12:17:43
    PointOfView
    Halo Horst,
    ich hab das gleiche Makro von Ken Puls auch verwendet und für mich etwas angepasst, wobei ich in mehreren Zellen Werte oder Namen für den Dateinamen übernehme. Aber das ist ja individuell anpassbar.
    Modul "basPDF"
    Option Explicit
    Sub PrintToPDF_Early()
    'Author : Ken Puls (www.excelguru.ca)
    'Macro Purpose: Print to PDF file using PDFCreator
    ' (Download from http://sourceforge.net/projects/pdfcreator/)
    ' Designed for early bind, set reference to PDFCreator
    Dim pdfjob As PDFCreator.clsPDFCreator
    Dim sPDFName As String
    Dim sPDFPath As String
    Dim Name As String
    Dim KDN As String
    Dim Ort As String
    Dim ANR As String
    Dim strFile As String
    Dim Datum As String
    Name = Range("C2").Value
    Ort = Range("C5").Value
    KDN = Range("C3").Value
    Datum = Format(Date$, "dd.mm.yy")
    ANR = "Angebot-Nr." & Range("C6").Value
    strFile = Name & " " & KDN & " " & Ort & " " & ANR & " - " & Datum & ".pdf" 'kann auch .bmp sein
    '/// Change the output file name here! ///
    sPDFName = strFile '"testPDF.pdf"
    'sPDFPath = ActiveWorkbook.Path & Application.PathSeparator
    sPDFPath = "\\Gtsv04\transfer\Fertigung\Lohnlackierung\Angebote\" 'Pfad anpassen
    'Check if worksheet is empty and exit if so
    If IsEmpty(ActiveSheet.UsedRange) Then Exit Sub
    Set pdfjob = New PDFCreator.clsPDFCreator
    With pdfjob
    If .cStart("/NoProcessingAtStartup") = False Then
    MsgBox "Can't initialize PDFCreator.", vbCritical + _
    vbOKOnly, "PrtPDFCreator"
    Exit Sub
    End If
    .cOption("UseAutosave") = 1
    .cOption("UseAutosaveDirectory") = 1
    .cOption("AutosaveDirectory") = sPDFPath
    .cOption("AutosaveFilename") = sPDFName
    .cOption("AutosaveFormat") = 0 ' 0 = PDF
    .cClearCache
    End With
    'Print the document to PDF
    ActiveSheet.PrintOut Copies:=1, ActivePrinter:="PDFCreator"
    'Wait until the print job has entered the print queue
    Do Until pdfjob.cCountOfPrintjobs = 1
    DoEvents
    Loop
    pdfjob.cPrinterStop = False
    'Wait until PDF creator is finished then release the objects
    Do Until pdfjob.cCountOfPrintjobs = 0
    DoEvents
    Loop
    pdfjob.cClose
    Set pdfjob = Nothing
    End Sub
    Zusätzlich prüfe ich über einem separatem Modul, ob der Verweis in der Objektbibliiothek vorhanden ist oder nicht:
    Modul "basVerweis"
    Option Explicit
    Public Sub ListReferencesInProject()
    Dim oRefs As Object ' References
    Dim oRef As Object ' Reference
    Dim i As Long
    Set oRefs = ActiveWorkbook.VBProject.References
    Range("A1") = "Bezeichnung"
    Range("B1") = "Name"
    Range("C1") = "Pfad"
    Range("D1") = "GUID"
    Range("E1") = "Major"
    Range("F1") = "Minor"
    Range("G1") = "Standard-Verweis"
    Range("A1:G1").Font.Bold = True
    i = 1
    For Each oRef In oRefs
    i = i + 1
    Cells(i, 1) = oRef.Description
    Cells(i, 2) = oRef.Name
    Cells(i, 3) = oRef.FullPath
    Cells(i, 4) = oRef.GUID
    Cells(i, 5) = oRef.Major
    Cells(i, 6) = oRef.Minor
    Cells(i, 7) = oRef.BuiltIn
    Next
    Range("A1:G1").EntireColumn.AutoFit
    Set oRefs = Nothing
    End Sub
    
    Public Sub Verweise_setzen()
    Call Verweis_prüfen_und_setzen
    End Sub
    

    Function Verweis_installiert(Verweisname) As Boolean
    Dim VBE As Object
    Dim x As Variant
    Verweis_installiert = False
    Set VBE = Application.VBE.ActiveVBProject
    With VBE
    For x = 1 To .References.Count
    If UCase(.References(x).Name) = UCase(Verweisname) Then
    Verweis_installiert = True
    Exit Function
    End If
    Next x
    End With
    End Function
    Sub Verweis_prüfen_und_setzen()
    If Verweis_installiert("PDFCreator") = True Then
    'MsgBox "Der VBA-Verweis PDFCreator ist vorhanden"
    Exit Sub
    End If
    If Verweis_installiert("PDFCreator") = False Then
    Verweis_PDFCreator
    'MsgBox "Der VBA-Verweis PDFCreator wurde erstellt"
    End If
    'MsgBox Verweis_installiert("PDFCreator")
    End Sub
    Public Sub Verweis_PDFCreator()
    ThisWorkbook.VBProject.References.AddFromGuid _
    GUID:="{1CE9DC08-9FBC-45C6-8A7C-4FE1E208A613}", Major:=6, Minor:=1
    End Sub
    

    Sub VerweisLoeschen()
    Dim sLink As String
    sLink = "PDFCreator"
    On Error GoTo ERRORHANDLER
    ActiveWorkbook.VBProject.References.Remove _
    ThisWorkbook.VBProject.References(sLink)
    Exit Sub
    ERRORHANDLER:
    'MsgBox "Verweis zu " & sLink & " wurde nicht gefunden!"
    End Sub Bei uns im Unternehmen, wir verwenden das an vielen Stellen im Haus, funktioniert es unter WinXP Pro (ink. SP3) und Excel 11 (2003) ausgezeichnet.
    Viele Grüsse
    PointOfView
    Oliver
    Anzeige
    AW: mit PDF Creator ein Tabellenblatt als pdf abspeich
    18.01.2010 13:44:09
    Horst
    Hallo
    vielen Dank für Deine Mühe.
    Ich habe Deinen Code getestet habe jedoch das gleiche Ergebnis erhalten.
    Die Ursache ist irgendwo in diesem Bereich und unseren (Netz)Einstellungen zu suchen.
    .cOption("UseAutosave") = 1
    .cOption("UseAutosaveDirectory") = 1
    Wenn ich Autosave = 0 setze, kommt die PDFCreator Oberfläche und ich kann die Umwandlung
    manuell starten, alles funktioniert wie gewollt.
    Ich Poste das ganze mal im Forum von PDFCreator. Vielleicht haben die ja einen Tip wo ich was
    ändern kann.
    Trotzdem nochmals vielen Dank.
    Gruß Horst

    317 Forumthreads zu ähnlichen Themen

    Anzeige
    Anzeige

    Beliebteste Forumthreads (12 Monate)

    Anzeige

    Beliebteste Forumthreads (12 Monate)

    Anzeige
    Anzeige
    Anzeige