Consulting

Results 1 to 7 of 7

Thread: Cube Values Timing Out When Batch Printing PDFs

  1. #1
    VBAX Newbie
    Joined
    Sep 2013
    Posts
    3
    Location

    Cube Values Timing Out When Batch Printing PDFs

    Good morning all,

    I'm currently trying to configure a macro that will cycle through each slicer that I have linked to a group of cube formulas and print that info as a PDF, move onto the next slicer and print that data set, etc. all the way through until the entire slicer list has been completed. I wrote the code below which works quite well up for a while, and then the cube values stop updating and I get a wonderful PDF that has ####### instead of the values of the cube formulas.

    Has anyone experienced this? I'm guessing it's due to consumption of RAM but was hoping that someone might have some insight or has run into this problem before? I tried putting a delay into the code to see if that would help, but even when I set it to run at a full 60 seconds between loops it's still erring out.

    Here is the code I am currently using:

    Sub Delay(NumberOfSeconds As Long)Dim Sec As Long
    Sec = Timer + NumberOfSeconds
    
    
    Do While Timer < Sec
    DoEvents
    Loop
    
    
    End Sub
    
    
    
    
    Sub SlicerLoop()
    
    
    
    
    Dim sC As SlicerCache
    Dim SL As SlicerCacheLevel
    Dim sI As SlicerItem
    Set sC = ActiveWorkbook.SlicerCaches("Slicer_1")
    Set SL = sC.SlicerCacheLevels(1)
    
    
    For Each sI In SL.SlicerItems
    sC.VisibleSlicerItemsList = Array(sI.Name)
    Application.CalculateBeforeSave = True
    Call Delay(5)
    ' Create and save .pdf
    Dim pdfName As String, FullName As String
    pdfName = Range("X1").Text
    FullName = "C:\Users\jwoidami\Desktop\Scorecards\" & pdfName & ".pdf"
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=FullName _
    , Quality:=xlQualityStandard, IncludeDocProperties:=False, _
    IgnorePrintAreas:=False, OpenAfterPublish:=False
    
    
    
    
    ActiveWorkbook.SlicerCaches("Slicer_1").ClearManualFilter
    
    
    
    
    Next
    
    
    End Sub

    Any insight or ideas would be greatly appreciated! this is really starting to get under my skin!

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    Welcome to the forum!

    Try a loop to check if the filename exists or have it check and compare FileLen() changes at some interval.

  3. #3
    VBAX Newbie
    Joined
    Sep 2013
    Posts
    3
    Location
    Thanks Kenneth! unfortunately the issue isn't with the length of the saved pdf, it's just the data not refreshing as the code loops through the slicer, so I'm not sure that solution would work unfortunately.

  4. #4
    It makes me so satisfied your vast understanding and wisdom have a new channel on the world. I am come a cross to your site and found it according to my need and demand.

  5. #5
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,646
    As far as I can see you overwrite the PDF each time (unless range("X1") changes it's value after each loop)
    There's no need to build any waiting procedure, because the next line will be executed only after finishing the previous one.
    This code might suffice:

    Sub M_snb() 
        For Each sI In ActiveWorkbook.SlicerCaches("Slicer_1").SlicerCacheLevels(1).SlicerItems 
            .Parent.Parent.VisibleSlicerItemsList = Array(sI.Name)
            ActiveSheet.ExportAsFixedFormat xlTypePDF, "C:\Users\jwoidami\Desktop\Scorecards\" & activesheet.range("X1").value & ".pdf"
        Next 
    End Sub

  6. #6
    VBAX Newbie
    Joined
    Sep 2013
    Posts
    3
    Location
    Hey snb, you're actually spot on, the range is tied to the slicer, so as the macro goes through each value in the slicer list, that value is populated into X1 so the save macro will save with whatever data is being displayed... Basically the value that's in cell X1 is:

    =CUBERANKEDMEMBER("PowerPivot Data",Slicer_1,1)
    Last edited by joeybb; 12-12-2013 at 09:49 AM. Reason: added code tags

  7. #7
    Thanks for help ...!

Posting Permissions

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