Printing to PDF

shippey121

Well-known Member
Joined
Mar 21, 2006
Messages
1,003
Morning all

i have a document that prints labels, the label has a template sheet and then VBA code cycles through data to populate each label and prints, if i print directly to the printer everything is fine and it prints in order.

what im wanting to do is print to PDF, i can sort the code to export to PDF but it does each print as a separate PDF and im wanting to combine them, i have tried using a PDF printer rather than exporting but it seems to mix them up and not put them in order, i need them in order, the PDF Printer im using is called PDF Creator, after the print finishes i have all the separate files and choose Merge as excel sends each page as a separate print

as you can see the code to print is pretty simple, any suggestions on how i could create a multi page document from 1 sheet

Code:
Sub print_labels()
Dim x As Long
Dim y As Long
Dim labels As Integer

On Error GoTo exitsub
x = InputBox("Enter number of Start Pallet")
y = InputBox("Enter number of Pallet Tickets required")
y = y - 1 + x

Sheets("labels").Select
For labels = x To y
Range("F3").Value = labels
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True

Next labels

exitsub:

Sheets("Summary Sheet").Select

End Sub
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
This creates a single PDF (named "All Labels.pdf" in the same folder as the macro workbook) with multiple pages, with each label starting on a new page.

Code:
Public Sub Print_Labels3()

    Dim s As Variant, n As Variant
    Dim labels As Integer
    Dim PDFworkbook As Workbook
    
    s = InputBox("Enter number of Start Pallet")
    If s = "" Then Exit Sub
    n = InputBox("Enter number of Pallet Tickets required")
    If n = "" Then Exit Sub
    
    Application.ScreenUpdating = False
    
    Set PDFworkbook = Workbooks.Add(xlWBATWorksheet)
    With ThisWorkbook.Worksheets("labels")
        For labels = s To s + n - 1
            .Range("F3").Value = labels
            .Copy After:=PDFworkbook.Worksheets(PDFworkbook.Worksheets.Count)
        Next labels
    End With
    
    With PDFworkbook
        .Worksheets(2).Select
        For n = 3 To Worksheets.Count
            .Worksheets(n).Select False
        Next
        .ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=ThisWorkbook.Path & "\All Labels.pdf", _
            Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
        .Close False
    End With

    ThisWorkbook.Worksheets("Summary Sheet").Activate
    
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0
Small correction.

Code:
        For n = 3 To Worksheets.Count

should be:

Code:
        For n = 3 To .Worksheets.Count
 
Upvote 0
Hi john

worked a treat,i did have to modify one part as it was stuck in and endless loop on this line
Code:
For labels = s To s + n - 1

i did sort of find another solution though this evening, using PDF Creator i pressed print and just set it to one page, when the dialog box pops up i choose MERGE, then when setting off the next batch of labels they queued up in the correct order

once finished i just click MERGE and the SAVE

i found your code and approach useful though and could probably use it on some other workbooks that are simliar

thanks again
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,159
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top