+ Reply to Thread
Results 1 to 10 of 10

Print to PDF with Looping

  1. #1
    Forum Contributor
    Join Date
    08-29-2012
    Location
    Manila, Philippines
    MS-Off Ver
    2019
    Posts
    102

    Print to PDF with Looping

    Good day gurus!

    First off, please take a look at the attached Excel workbook to get a good grip of the challenge I am currently facing

    Now to the query.

    I have a task to populate a form and save it as PDF. It is actually a resume database and all entries/fields are in Excel sheet. Easy, right? Easy to manually do it if there are only say 5 to 10 resumes, and convert them to PDF one by one. The problem arise as the there are as of the moment, close to 100 different entries/resumes that I need to convert to PDF. I will be needing a system that loops through the ID Number in "DATABASE" sheet, get the information per row that correspond to that ID number and send to "RESUME FORM" sheet, and convert that sheet to PDF. I should end up with multiple pages of PDF file.

    I am quite confident that gurus here will be able to find a solution to this challenge, as I have been posting questions here before with more complicated systems. Hope you guys an help me with this.

    Thanks in advance!
    Attached Files Attached Files

  2. #2
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,760

    Re: Print to PDF with Looping

    Perhaps something like this?

    Please Login or Register  to view this content.
    This will save the pdf file to the folder C:\Temp so you will need to change this to the folder of your choice. Don't forget to add the last backslash or the macro will not work.

    This string works "C:\Temp\" but not one like this "C:\Temp"

    The pdf file name is set up as "Form_ID number" so change the string fName if you like a more descriptive name.

    Alf

  3. #3
    Forum Contributor
    Join Date
    08-29-2012
    Location
    Manila, Philippines
    MS-Off Ver
    2019
    Posts
    102

    Re: Print to PDF with Looping

    Quote Originally Posted by Alf View Post
    Perhaps something like this?

    Please Login or Register  to view this content.
    This will save the pdf file to the folder C:\Temp so you will need to change this to the folder of your choice. Don't forget to add the last backslash or the macro will not work.

    This string works "C:\Temp\" but not one like this "C:\Temp"

    The pdf file name is set up as "Form_ID number" so change the string fName if you like a more descriptive name.

    Alf
    Works like a charm! Insane skills you have there, good sir! Thanks for giving solution to my problem.

    One last thing, though you opt not to do this since your code has done a great job. But if it still possible to have everything in 1 PDF, I will take it. But for now, please take my Reputation Points! :D

  4. #4
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,760

    Re: Print to PDF with Looping

    I should end up with multiple pages of PDF file.
    Oooooops I missed that part but as this is New Years eve and I'm of to friends of mine to celebrate I'll have a go at it tomorrow.

    Thanks for feedback and rep

    A happy New Year to you Sir.

    Regards

    Alf

  5. #5
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,914

    Re: Print to PDF with Looping

    See if this is what you're looking for.

    Please Login or Register  to view this content.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  6. #6
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,760

    Re: Print to PDF with Looping

    Having checked the macro posted by bakerman2 I think this is the solution you was looking for and as I have no better ideas I'll just relax.

    The only thing that worries me is that in your uploaded file you use the "RANDBETWEEN" function for "AGE" and "WORK_EXPERIENCE". As both "RAND" and "RANDBETWEEN" are volatile function i.e. every time a change occur the values for "AGE" and "WORK_EXPERIENCE" will be updated with new values.

    If you do wish to have fix values for these parameters you either use fixed values instead of "RANDBETWEEN" or you set calculation to "Manual".

    Adding the line

    Please Login or Register  to view this content.
    at the start of the macro should freeze the "AGE" and ""WORK_EXPERIENCE" values during the macro run and adding the line

    Please Login or Register  to view this content.
    at the end of the macro should restore things to normal.

    Alf

  7. #7
    Forum Contributor
    Join Date
    08-29-2012
    Location
    Manila, Philippines
    MS-Off Ver
    2019
    Posts
    102

    Re: Print to PDF with Looping

    Hello gurus, sorry for late replies. Had a blast this new year :D

    Thanks for still taking the challenge I posted. Your inputs really helped me a lot!

    @Alf, the RANDBETWEEN function is just for sample purposes. At that time I was a bit lazy to come up with random numbers for the sample, so I thought of do it automatically. The final file I am working on has fixed values for age.

    And one last thing before I set this thread to SOLVED, a new direction just surfaced and in addition, they wanted to instead of multiple PDF pages, they are now requiring me to loop it and ended up with multiple sheets of "RESUME FORM". I already solved this, but my problem now is to rename the sheets with based on LAST_NAME. I attempted to do this using
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    But an error persist saying that the name has been used already. Hope you can help me with this one last challenge.

    Thanks in advance!

  8. #8
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,760

    Re: Print to PDF with Looping

    In your uploaded file the E2 value in the sheet "RESUME FORM" is the "LASTENAME" so if you got two or more entries where the last name is the same then you will get this error message as the macro line you use for naming the sheet is correct.

    You could either check all names and see to that all names are unique or you could use a combination of last name and ID add a bit of code to the macro i.e.

    Please Login or Register  to view this content.
    Alf

  9. #9
    Forum Contributor
    Join Date
    08-29-2012
    Location
    Manila, Philippines
    MS-Off Ver
    2019
    Posts
    102

    Re: Print to PDF with Looping

    Quote Originally Posted by Alf View Post
    In your uploaded file the E2 value in the sheet "RESUME FORM" is the "LASTENAME" so if you got two or more entries where the last name is the same then you will get this error message as the macro line you use for naming the sheet is correct.

    You could either check all names and see to that all names are unique or you could use a combination of last name and ID add a bit of code to the macro i.e.

    Please Login or Register  to view this content.
    Alf
    Thank sir for the follow-up answer. Your inputs are very helpful!

    And apologies for taking this long to mark this thread as SOLVED.

  10. #10
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,760

    Re: Print to PDF with Looping

    apologies for taking this long to mark this thread as SOLVED
    No problem

    Alf

+ 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. Trying to Build a Looping Print Macro
    By baersarke in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-13-2016, 04:06 PM
  2. Looping through list box selections to print range to PPTX
    By e30325i in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-01-2014, 02:10 PM
  3. Disabled print toolbar and menu but Print Macro button cannot print also...
    By zein97 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-22-2014, 01:42 PM
  4. Set print area of selected range then print preview if ok then print the document!
    By HaroonSid in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-01-2014, 07:10 AM
  5. Do Until Looping (not looping through all other columns)
    By orle8050 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-11-2013, 10:37 AM
  6. VBA to set print range, open box asking for print qty, print, then redefine print area
    By galvinpaddy in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-11-2012, 06:43 PM
  7. Looping a print report through a series of records
    By AGM in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-22-2005, 04:25 AM

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