• Privacywetgeving
    Het is bij Helpmij.nl niet toegestaan om persoonsgegevens in een voorbeeld te plaatsen. Alle voorbeelden die persoonsgegevens bevatten zullen zonder opgaaf van reden verwijderd worden. In de vraag zal specifiek vermeld moeten worden dat het om fictieve namen gaat.

Een PDF maken van een selectie in Excel

Status
Niet open voor verdere reacties.

HarryBee

Gebruiker
Lid geworden
8 jul 2008
Berichten
240
Hallo iedereen,

Mijn volgende vraag is, hoe print ik d.m.v. een knop, een pdf nadat bepaalde gegevens, die voldoen aan een voorwaarde, automatisch geselecteerd worden?

Voorbeeld:

Blad 1 bestaat uit 10 kolommen met financiële gegevens. Elke rij heeft een nummer. En heeft ook een omschrijving. De bedoeling is dat na het indrukken van een knop een selectie gemaakt wordt op grond van een vaste voorwaarde. (bijv. alle records die op "Betaald" staan van deze maand en dan alleen kolom 1, 3, 7,9 en 10) die dan vervolgens naar een PDF geprint worden en in een vaste Map wordt geplaatst.

Ik blijf maar tobben met selecties. Hoe kan ik dat realiseren?:rolleyes:

Iemand een suggestie?

Alvast bedankt.

Groeten Harry
 
Ik zou een heel werkblad selecteren en van deze een pdf maken. Zie onderstaande code
HTML:
Sub PDF_Schiedam()

    Dim FileExtStr As String
    Dim FileFormatNum As Long
    Dim Sourcewb As Workbook
    Dim Destwb As Workbook
    Dim TempFilePath As String
    Dim TempFileName As String
    Dim OutApp As Object
    Dim sh As Worksheet

    Userform2.Show 0
    
    DoEvents
    
    With Application
        .ScreenUpdating = False
        .EnableEvents = False
    End With
    
    Sheets("Blad 1").Select
    ActiveSheet.Unprotect
            
    Set Sourcewb = ActiveWorkbook
 
    'Copy the sheets to a new workbook
    Sourcewb.Sheets(Array("Blad 1")).Copy
    Set Destwb = ActiveWorkbook
 
    'Determine the Excel version and file extension/format
    With Destwb
        If Val(Application.Version) < 12 Then
            'You use Excel 97-2003
            FileExtStr = ".xls": FileFormatNum = -4143
        Else
            'You use Excel 2007
            'We exit the sub when your answer is NO in the security dialog that you only
            'see  when you copy a sheet from a xlsm file with macro's disabled.
            If Sourcewb.Name = .Name Then
                With Application
                    .ScreenUpdating = True
                    .EnableEvents = True
                End With
                MsgBox "Your answer is NO in the security dialog"
                Exit Sub
            Else
                Select Case Sourcewb.FileFormat
                Case 51: FileExtStr = ".xlsx": FileFormatNum = 51
                Case 52:
                    If .HasVBProject Then
                        FileExtStr = ".xlsm": FileFormatNum = 52
                    Else
                        FileExtStr = ".xlsx": FileFormatNum = 51
                    End If
                Case 56: FileExtStr = ".xls": FileFormatNum = 56
                Case Else: FileExtStr = ".xlsb": FileFormatNum = 50
                End Select
            End If
        End If
    End With
         
        For Each sh In Destwb.Worksheets
            sh.Select
            With sh.UsedRange
                .Cells.Copy
                .Cells.PasteSpecial xlPasteValues
                .Cells(1).Select
            End With
            Application.CutCopyMode = False
            Destwb.Worksheets(1).Select
        Next sh
    
     With Application
        .ScreenUpdating = True
        .EnableEvents = True
    End With

'Save the new workbook/Mail it/Delete it
    'TempFilePath = Environ$("temp") & "\"
    'TempFileName = "test"
    
    'With Destwb
        '.SaveAs TempFilePath & TempFileName & FileExtStr, FileFormat:=FileFormatNum
    'End With
    
'Printcode
    Sheets(Array("Blad 1")).Select
    Sheets("Blad 1").Activate
    Application.ActivePrinter = "CutePDF Writer op CPW2:"
    ActiveWindow.SelectedSheets.PrintOut Copies:=1, ActivePrinter:= _
        "CutePDF Writer op CPW2:", Collate:=True
' This set of code tells the macro to pause for 2 seconds. This will allow for the PDF printer to run through its process and prompt you for a filename.
    newHour = Hour(Now())
    newMinute = Minute(Now())
    newSecond = Second(Now()) + 2
    waitTime = TimeSerial(newHour, newMinute, newSecond)
    Application.Wait waitTime
' This line of code specifies your directory as well as the cell or range which you want the filename to come from.

    Filename = "C:\test\test.pdf"

'Filename = "D:\Business Files\PDF Files\" & ActiveSheet.Range("InvNbr").Value & ".pdf"
' This line of code sends the filename characters and the ENTER key to the active application (i.e. the prompt window). The "False" statement allows the macro to continue running without waiting for the keys to be processed.

    SendKeys Filename & "{ENTER}", True
  
    'Delete the file you have created
    
    ActiveWorkbook.Close Saved = True
    
    
     
    Sourcewb.Activate
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan