Tijd weergeven in naam bestand

Status
Niet open voor verdere reacties.

jostridec

Gebruiker
Lid geworden
20 sep 2011
Berichten
7
Hallo,

Ik ben met Excel 2003 bezig om een rapport met grafieken en gegevens af te drukken. Ik druk dit af in een PDF bestand. Om verwarring en overschrijving te verkomen wil ik de tijd en datum in de bestandsnaam schrijven. Deze heb ik ook in mijn rapport staan die ik afdruk. Ik doe dit met de volgende code:

Code:
Sub PrintPDF()
    
    Dim pdfjob As Object
    Dim sPDFName As String
    Dim sPDFPath As String

    '/// Change the output file name here! ///
    sPDFName = Sheets("Blad2").Range("B7") & "_" & Sheets("Blad2").Range("H7") & "_" & Sheets("Blad2").Range("H8")
    sPDFPath = ActiveWorkbook.Path & Application.PathSeparator

    'Check if worksheet is empty and exit if so
    If IsEmpty(ActiveSheet.UsedRange) Then Exit Sub

    Set pdfjob = CreateObject("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: mad:: mad:
    Set pdfjob = Nothing
    
   ActiveWorkbook.Saved = True
   Application.Quit
End Sub

In cel B7 staat tekst: TEST
In cel H7 staat de datum in deze notatie: 22-09-2011 (celeigenschappen is ingesteld als datum)
In cel H8 staat de tijd in deze notatie: 10:43:05 (celeigenschappen is ingesteld als tijd)

Als ik de macro uitvoer krijg ik de volgende bestandsnaam: TEST_22-9-2011_0,446585648148148.pdf

Met de datum gaat het goed, maar met de tijd niet. Snap niet hoe dat?
 
Code:
sPDFName = Sheets("Blad2").Range("B7") & "_" & Sheets("Blad2").Range("H7") & "_" & Format(Sheets("Blad2").Range("H8"), "hh:mm:ss")
 
Status
Niet open voor verdere reacties.
Steun Ons

Nieuwste berichten

Terug
Bovenaan Onderaan