+ Reply to Thread
Results 1 to 4 of 4

Batch exporting of dynamic page to PDF

Hybrid View

  1. #1
    Registered User
    Join Date
    09-18-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    35

    Post Batch exporting of dynamic page to PDF

    I'm looking in ways of making PDFs of a single page of Excel, whose content changes dynamically depending on a variable. I can't imagine I'm the first looking for this, but I couldn't find any information...

    More concretely, let's say I have a huge table where I put in details of an order of a client (personal information, what he has ordered, how many, costs, etc.). On a different page I have a nicely formatted invoice, which I want to export to a PDF to send to the client. I just fill in the InvoiceID and the whole page is ready for export.

    However, let's say I need to do this weekly for hundreds of invoices. This means that I need to start with InvoiceID_000, export to PDF, change the corresponding cell to InvoiceID_001, export to PDF, change the cell InvoiceID_002, export to PDF, etc. A lot of work. So I'd need something that can loop through all InvoiceIDs and export the page per InvoiceID.

    I'd say something like:
    for low(InvoiceID) to high(InvoiceID) do
    begin
    export page to PDF with name "InvoiceID" in location XXX;
    end;
    Is this doable? Can someone guide me in the right direction? I have no experience with VBA, but I'm sufficiently experienced with mathematical programming and the "normal" Excel functions. Thanks!

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Batch exporting of dynamic page to PDF

    Try something like this.

    Change the red items to suit;
    • invoice start and end ID numbers
    • the "corresponding cell" sheet name and cell address
    • Sheet Name to save as PDF
    • File path for the PDF file

    Sub Save_Invoice_PDFs()
        
        Dim IDStart As Long, IDEnd As Long, ID As Long, strID As String
        
        IDStart = 1 'Invoice start number
        IDEnd = 10  'Invoice end number
        
        For ID = IDStart To IDEnd
        
            'Format ID number
            strID = "InvoiceID_" & Format(ID, "000")
            
            'Write ID number to 'corresponding cell'.
            Sheets("Sheet1").Range("A1").Value = strID
            
            'Save sheet as PDF
            Sheets("Sheet1").ExportAsFixedFormat _
                                Type:=xlTypePDF, _
                                Filename:="C:\MyFolder\" & strID & ".pdf", _
                                Quality:=xlQualityStandard, _
                                IncludeDocProperties:=True, _
                                IgnorePrintAreas:=False, _
                                OpenAfterPublish:=False
                                
        Next ID
        
        MsgBox "Invoices saved as PDF.", , "Invoice Save Complete"
        
    End Sub
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    09-18-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    35

    Re: Batch exporting of dynamic page to PDF

    Sorry for the late response, it took a while for me to test it in Windows. It doesn't work on the Mac, but perfectly on Windows! Thanks for making an entire working script!

    Excel on Mac says
    Print
    Error while printing
    and then, in an additional message box
    Run-time error '1004':
    Application-defined or object-defined error
    If there is a suggestion what the problem might be, that would be great and very practical for me.

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Batch exporting of dynamic page to PDF

    I can't help much with Mac code. Perhaps the example code from this site mite help.

    Make and Mail PDF files with VBA code on your Mac

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Exporting the first page as PDF
    By naga in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-26-2016, 03:50 AM
  2. Replies: 1
    Last Post: 04-20-2013, 07:00 PM
  3. Exporting from web page via VBA
    By dementia in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-07-2013, 04:35 PM
  4. Exporting as text only, in page order
    By rickwtx in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-12-2011, 12:18 PM
  5. Exporting Charts on to a Web Page
    By mattdick in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-24-2009, 01:17 PM
  6. Exporting conditional formatting to a web page
    By lusiocoram in forum Excel General
    Replies: 3
    Last Post: 11-13-2008, 11:35 AM
  7. Batch Inserting Row Sheets in between page breaks
    By TeraFractal in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-07-2008, 06:40 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1