+ Reply to Thread
Results 1 to 8 of 8

Macro for Looping Through Slicer and Saving as PDF writing over same PDF

  1. #1
    Registered User
    Join Date
    05-04-2017
    Location
    California
    MS-Off Ver
    Newest
    Posts
    7

    Macro for Looping Through Slicer and Saving as PDF writing over same PDF

    Hi All,

    I am trying to loop through each option in my Slicer and save a pdf version of the dashboard which populates to show all the rep data which I then want to save to the selected file path. I should be ending up with 30 pdf's. The macro loops through just fine but it only saves one copy called NEW.pdf which it repeatedly writes over as it goes through each slicer. Here is the code I am using:

    Please Login or Register  to view this content.
    Any help would be greatly appreciated as I am super frantically trying to get this working for my job and this is quite over my head!

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Macro for Looping Through Slicer and Saving as PDF writing over same PDF

    I'm going to guess that the value in L13 is not changing uniquely as each slicer value is applied. Add this debug line, run the code. When it completes, go into the VBEditor and check the Immediate Window (CTRL+G to open it) and look at all the individual filenames, are they all the same?

    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    05-04-2017
    Location
    California
    MS-Off Ver
    Newest
    Posts
    7

    Re: Macro for Looping Through Slicer and Saving as PDF writing over same PDF

    Thank you so much for the quick reply!!! I put in the code as you said and looked at the Immediate Window- you are right, they are all listed as this:
    L:\XYZ\Sales Ops\K\NEW.pdf

    Why is this happening and how can I resolve? The file names should be unique for each rep and save individual pdf's.

  4. #4
    Registered User
    Join Date
    05-04-2017
    Location
    California
    MS-Off Ver
    Newest
    Posts
    7

    Re: Macro for Looping Through Slicer and Saving as PDF writing over same PDF

    Also to my knowledge L13 is supposed to be pulling in the rep name selected from the slicer as it runs though- I have stopped the macro half way and seen that it is doing so but somehow its not saving that way, UGH!

  5. #5
    Registered User
    Join Date
    05-04-2017
    Location
    California
    MS-Off Ver
    Newest
    Posts
    7

    Re: Macro for Looping Through Slicer and Saving as PDF writing over same PDF

    Hi Jerry,

    Do you have any thoughts on how to fix? You were right on the money with the error!

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Macro for Looping Through Slicer and Saving as PDF writing over same PDF

    If you look, you'll notice there is NO value from L13 being used. Your filenames are simply the text you are feeding it. Does this work any better?

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    05-04-2017
    Location
    California
    MS-Off Ver
    Newest
    Posts
    7

    Re: Macro for Looping Through Slicer and Saving as PDF writing over same PDF

    Hi Jerry,

    Thank you!!! I was able to fix using the following change:

    Please Login or Register  to view this content.
    However I noticed the files are saving out in the K folder with NEW before each rep name in the pdf file name. It seems they aren't saving out in the New folder with just the rep name as the file name which is what populates in cell L13. Somehow its taking New as part of the file name rather than the location. Any ideas as to how to fix? Thanks in advance!!

  8. #8
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Macro for Looping Through Slicer and Saving as PDF writing over same PDF

    Your text string, add in the missing \ for NEW\

+ 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. looping through folders - saving xls files as PDFs
    By Hugh Jass in forum Excel General
    Replies: 1
    Last Post: 05-11-2016, 06:06 PM
  2. looping through folders - saving xls files as PDFs
    By Hugh Jass in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-11-2016, 06:06 PM
  3. [SOLVED] Writing Slicer Items to Sheet- Modifying Existing Code
    By liquidmettle in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-14-2016, 11:15 AM
  4. [SOLVED] Error checking code that will prevent over-writing of a workbook when saving to PDF
    By mike_vr in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-02-2012, 10:11 AM
  5. Slicer Macro - unfilter another slicer on selection
    By chadheins in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-24-2012, 10:41 AM
  6. [SOLVED] Change Chart Title Depending on a Slicer - slicer advice
    By JungleJme in forum Excel General
    Replies: 8
    Last Post: 08-17-2012, 07:59 AM
  7. Importing, looping and saving (not really solved)
    By stevencohen in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-25-2011, 02:10 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