+ Reply to Thread
Results 1 to 5 of 5

Macro Needed to Loop, Save, and Name Excel Files as PDFs

  1. #1
    Registered User
    Join Date
    03-08-2012
    Location
    Boston, MA
    MS-Off Ver
    Excel 2010
    Posts
    4

    Macro Needed to Loop, Save, and Name Excel Files as PDFs

    Macro Help.xlsm

    In Excel 2010, I have a database on Sheet 1 with rows of people's personal information and a printable/formatted "document" on Sheet 2. I have a macro that indexes through each row of the database and prints the document hard-copy. What I need now instead of printing hard-copy, is to generate a single document for each index number (i.e. row of data) and have that save as a pdf with the name of the document based on one of the data cells, either from the database or the document itself. For instance, if index number one is Joe Smith in the database, when the maro runs, the formatted documents pulls all of Joe's personal information, saves it as a pdf with JoeSmith.pdf as the name (or his birthdate.pdf as the name).

    Below is my code for the index looping and printing through the first 15 entries in the database.

    Please Login or Register  to view this content.
    Last edited by ahkarchem; 06-08-2012 at 02:59 PM.

  2. #2
    Registered User
    Join Date
    03-08-2012
    Location
    Boston, MA
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Macro Needed to Loop, Save, and Name Excel Files as PDFs

    Bump - no response.

  3. #3
    Valued Forum Contributor blane245's Avatar
    Join Date
    02-20-2009
    Location
    Melbourne, FL
    MS-Off Ver
    Excel 2010
    Posts
    649

    Re: Macro Needed to Loop, Save, and Name Excel Files as PDFs

    The code below is the result of recording a "Save As" operation with a file type of PDF selected. I have put something generic in the file name that you will have to adjust based on how you want to name the file. Note that the workshhet that you want to save must be activated first.
    Please Login or Register  to view this content.
    Bob
    Click my star if my answer helped you. Mark the thread as [SOLVED] if it has been.

  4. #4
    Registered User
    Join Date
    03-08-2012
    Location
    Boston, MA
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Macro Needed to Loop, Save, and Name Excel Files as PDFs

    This is working for creating the pdf file, but I am not sure how to get the file name to generate based on one of the data fields on the statement. Right now, it just keeps saving over the previous pdf it created. Any suggestions how I can get the file to pull the id number from cell f3?

  5. #5
    Valued Forum Contributor blane245's Avatar
    Join Date
    02-20-2009
    Location
    Melbourne, FL
    MS-Off Ver
    Excel 2010
    Posts
    649

    Re: Macro Needed to Loop, Save, and Name Excel Files as PDFs

    I assume you are talking about the contents of F3 on the active sheet. If that is the case, then you can set the file name parameter to something like
    FileName:="File" & ActiveSheet.F3.Value & ".pdf"
    You can vary the prefix and suffix for the F3 contents as you see fit.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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