+ Reply to Thread
Results 1 to 25 of 25

Print to individual PDF files from list of Yes/No

  1. #1
    Registered User
    Join Date
    06-06-2019
    Location
    Blaine, Minnesota USA
    MS-Off Ver
    2013, 2016
    Posts
    15

    Print to individual PDF files from list of Yes/No

    Hello,

    I am rather new to VBA and having a good time browsing the forum finding code that seems to work well for the most part to fit my needs.

    I have a spreadsheet with a large number of worksheets that I want printed to individual PDF files that correspond to the worksheet name. Currently my code will spit out all the "Yes" files to be printed in one single pdf.
    I seem to be lost on how to get an if statement and a with statement to work together to print individual PDF files.


    Please Login or Register  to view this content.
    Any help would be greatly appreciated!

    Thanks,
    Jonathan
    Last edited by jkhuskies; 06-23-2019 at 11:41 PM.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,366

    Re: Print to individual PDF files from list of Yes/No

    Untested, but maybe:

    Please Login or Register  to view this content.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Print to individual PDF files from list of Yes/No

    Have you thought of saving (exporting) as PDF, this might make it easier, you do not need an array and just save each (work)sheet as an individual PDF file.

    Please Login or Register  to view this content.
    Pass the worskheet name as parameter ...
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

  4. #4
    Registered User
    Join Date
    06-06-2019
    Location
    Blaine, Minnesota USA
    MS-Off Ver
    2013, 2016
    Posts
    15

    Re: Print to individual PDF files from list of Yes/No

    Hi Trevor,

    The only complaint I have about this code you provided is I have to enter the name of the sheet in the save dialog box. I want it to pull the sheet name automatically.

    I have code embedded in each worksheet (shown below) that is to be printed, this will print each individual worksheet by hand and uses the worksheet name.
    This also makes it so that it doesn't print out to actual paper which is an issue for other people that have default settings as such.

    Is there a way to incorporate something like this into the code you provided?
    I did some testing and not sure how to do that.

    Please Login or Register  to view this content.
    Thank you,
    Jonathan

  5. #5
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Print to individual PDF files from list of Yes/No

    Did you try mine?

  6. #6
    Registered User
    Join Date
    06-06-2019
    Location
    Blaine, Minnesota USA
    MS-Off Ver
    2013, 2016
    Posts
    15

    Re: Print to individual PDF files from list of Yes/No

    Hi Keebellah,

    I got an ambiguous argument, and I was unable to run or assign to a macro button.

    Not sure what is going on.

    Thanks,
    Jonathan

  7. #7
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Print to individual PDF files from list of Yes/No

    That means you’ve got two macros with the same name

  8. #8
    Registered User
    Join Date
    06-06-2019
    Location
    Blaine, Minnesota USA
    MS-Off Ver
    2013, 2016
    Posts
    15

    Re: Print to individual PDF files from list of Yes/No

    I looked and only one macro of each with unique name.
    I even changed the name and removed the "public" just to see if it allows me to run the macro and I get nothing still.

  9. #9
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Print to individual PDF files from list of Yes/No

    Ambiguous means just that, you might have overlooked, open the VBA Editor press Ctrl + F en enter the macroname and make sure you sear the entire project (checkbox) it's there somewhere

  10. #10
    Registered User
    Join Date
    06-06-2019
    Location
    Blaine, Minnesota USA
    MS-Off Ver
    2013, 2016
    Posts
    15

    Re: Print to individual PDF files from list of Yes/No

    Thanks for the idea. I just don't see any other macro with the same name.

    I have attached all my code below.

    Attachment 629676

    Please Login or Register  to view this content.

  11. #11
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,366

    Re: Print to individual PDF files from list of Yes/No

    You said
    I got an ambiguous argument
    That's not the same as an ambiguous name.

  12. #12
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Print to individual PDF files from list of Yes/No

    True, but I suggest the file attached and see for ourselves.

  13. #13
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,366

    Re: Print to individual PDF files from list of Yes/No

    No argument.

  14. #14
    Registered User
    Join Date
    06-06-2019
    Location
    Blaine, Minnesota USA
    MS-Off Ver
    2013, 2016
    Posts
    15

    Re: Print to individual PDF files from list of Yes/No

    Are you talking about your code you posted earlier?

    Otherwise I don't see an attachment. I have attached a slimmed down version of my Excel file for reference.

    I still can't get either code to do individual printouts.
    Attached Files Attached Files
    Last edited by jkhuskies; 06-26-2019 at 09:31 AM.

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

    Re: Print to individual PDF files from list of Yes/No

    Here's you're error. The 'e' isn't supposed to be there.
    Please Login or Register  to view this content.
    To print all sheets to individual pdf's this is all you need.

    Please Login or Register  to view this content.
    Last edited by bakerman2; 06-26-2019 at 09:46 AM.
    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.

  16. #16
    Registered User
    Join Date
    06-06-2019
    Location
    Blaine, Minnesota USA
    MS-Off Ver
    2013, 2016
    Posts
    15

    Re: Print to individual PDF files from list of Yes/No

    I get a compile error "argument not optional".

    I changed the following code and it runs now.

    Please Login or Register  to view this content.
    Last edited by jkhuskies; 06-26-2019 at 10:01 AM.

  17. #17
    Registered User
    Join Date
    06-06-2019
    Location
    Blaine, Minnesota USA
    MS-Off Ver
    2013, 2016
    Posts
    15

    Re: Print to individual PDF files from list of Yes/No

    Working code is below.

    Please Login or Register  to view this content.
    Solved
    Last edited by jkhuskies; 06-26-2019 at 10:13 AM.

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

    Re: Print to individual PDF files from list of Yes/No

    Glad you got it solved and thanks for rep+.

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

  19. #19
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Print to individual PDF files from list of Yes/No

    Code works great just a note about the formulas, you should avoid #N/A add extra checks makes the sheet sloppy

  20. #20
    Registered User
    Join Date
    06-06-2019
    Location
    Blaine, Minnesota USA
    MS-Off Ver
    2013, 2016
    Posts
    15

    Re: Print to individual PDF files from list of Yes/No

    Hello Keebellah,

    I now have a run-time error '5': Invalid procedure call or argument.
    I even went back and tried the original code which doesn't work. I'm not sure why it's failing now.

    Maybe you could take a look ?

    Please Login or Register  to view this content.
    Thanks,
    Jonathan
    Last edited by jkhuskies; 07-01-2019 at 10:40 AM.

  21. #21
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Print to individual PDF files from list of Yes/No

    No error here (of courese tested with another path) but maybe that's the problem.
    Does the path exist?

  22. #22
    Registered User
    Join Date
    06-06-2019
    Location
    Blaine, Minnesota USA
    MS-Off Ver
    2013, 2016
    Posts
    15

    Re: Print to individual PDF files from list of Yes/No

    It's weird I have a test file and a completed file. The code works on the test file but not the completed file, the file path is the same for both.

    I did do some changes to the completed file on which worksheets are being printed but that should not effect the macro, only which ones it will print/not print.

    I'll try and duplicate the changes to the test file to see if it has any affects on the worksheet.

    I have attached a couple images of the cells I changed.

    Thanks,
    Jonathan
    change on sheets.jpg

    summary sheet.jpg

  23. #23
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Print to individual PDF files from list of Yes/No

    Troubleshooting is the most time consuming part of coding.
    Just run the macro line by line.
    Open the VBA editor and select the printall macro, then Press F8 to start the macro and just press F8 for each one of code until it hits the error
    The images you attach don't tell me anything, maybe check if the range / cell you query for the N value is not a merged cell.

  24. #24
    Registered User
    Join Date
    06-06-2019
    Location
    Blaine, Minnesota USA
    MS-Off Ver
    2013, 2016
    Posts
    15

    Re: Print to individual PDF files from list of Yes/No

    I was able to fix it. Regardless of a "Y" or "N" it should have been printing something.
    What I had changed was a formula before not code so it makes no sense.
    I changed another formula in the summary worksheet and it started working again.

    I've gone through the whole line by line in the past but none that gave this much of a headache.

    Thanks for the help!

  25. #25
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Print to individual PDF files from list of Yes/No

    I didn't do much, you did it all

+ 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. Use VBA to zip individual files in a folder to individual zip files
    By bhanu3938 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-27-2018, 04:38 AM
  2. Print all options from dropdown list to PDF and name the files the exact names in the list
    By johnwilliamboyle in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-17-2014, 11:49 AM
  3. Export Individual Rows To Individual Text Files?
    By jimmer18 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 01-13-2014, 11:43 AM
  4. Outputting individual cells to individual text files
    By db9429 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-17-2013, 03:39 PM
  5. Replies: 1
    Last Post: 01-31-2012, 09:07 PM
  6. Replies: 1
    Last Post: 05-22-2006, 05:40 PM
  7. [SOLVED] how do I print .doc files from a list of pathnames in a spreadshee
    By Dal in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-05-2006, 11:10 AM

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