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

Blatt als PDF-Datei abspeichern

Blatt als PDF-Datei abspeichern
WalterK
Hallo,
in der Recherche habe ich einen Code gefunden mit dem Blätter als PDF-Datei gespeichert werden. Auf meine Bedürfnisse angepasst funktioniert er tadellos.
Eine kleine Änderung bekomme ich aber nicht hin.
Es geht um die Zeile sPDFName = "Arbeitszeitnachweis .....
MonatJahr bezieht sich auf die Zelle AX1 und dort steht ein Datum im Format 01.01.2010
Ich möchte aber, das im PDFName das Datum im Format 2010.01 steht.
Wer kann mir diese kleine Änderung einbauen?
Hier noch der Codeteil:
Option Explicit
Sub PrintToPDF_Early_Arbeitszeitnachweis()
'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 MonatJahr As String
Name = Range("R1").Value
MonatJahr = Range("AX1").Value
'/// Change the output file name here! ///
sPDFName = "Arbeitszeitnachweis" & "_" & Name & "_" & MonatJahr & ".pdf"
sPDFPath = ActiveWorkbook.Path & Application.PathSeparator
'Check if worksheet is empty and exit if so
If IsEmpty(ActiveSheet.UsedRange) Then Exit Sub
Set pdfjob = New PDFCreator.clsPDFCreator
usw.
Besten Dank uns Servus, Walter

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

Betreff
Benutzer
Anzeige
AW: Blatt als PDF-Datei abspeichern
16.07.2010 22:10:25
Josef

Hallo Walter,
MonatJahr = Format(Range("AX1"), "yyyy.MM")


Gruß Sepp

Genau so, besten Dank! Servus, Walter
16.07.2010 22:17:34
WalterK
Neues Problem und komische Sache..
16.07.2010 22:33:34
WalterK
Hallo,
ich habe jetzt den Code mehrmals probiert und hat auch immer funktioniert.
Jetzt plötzlich kommt die Fehlermeldung: Can't initialize PDFCreator.
Kann mir jemand sagen, was ich hier falsch mache?
Hier noch zur Info der vollständige Code:
Option Explicit
Sub PrintToPDF_Early_Arbeitszeitnachweis()
'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 MonatJahr As String
Name = Range("R1").Value
MonatJahr = Format(Range("L2"), "yyyy.MM")
Application.ScreenUpdating = False
'/// Change the output file name here! ///
sPDFName = "Arbeitszeitnachweis" & "_" & Name & "_" & MonatJahr & ".pdf"
sPDFPath = ActiveWorkbook.Path & Application.PathSeparator
'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
'   Dim WsShell
'   Dim intText As Integer
'   Set WsShell = CreateObject("WScript.Shell")
'   intText = WsShell.Popup("Das Blatt wurde jetzt als PDF-Datei gespeichert.", 2, "Hinweis..... _
")
Application.ScreenUpdating = True
End Sub
Servus, Walter
Anzeige
Vergessen auf offen zu setzen
16.07.2010 22:34:19
WalterK
Thema erledigt
17.07.2010 09:40:05
WalterK
Hallo,
habe in der Recherche noch gelesen, dass es eventuell mit einer "Pause im Loop" funktioniert.
Und das tut es auch seit ich die Pause eingebaut habe.
Servus, Walter

346 Forumthreads zu ähnlichen Themen

Anzeige
Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige