PAX API: Multiple commit of all quick reports (or other ways?)

Post Reply
User avatar
Elessar
Community Contributor
Posts: 358
Joined: Mon Nov 21, 2011 12:33 pm
OLAP Product: PA 2
Version: 2.0.9
Excel Version: 2016
Contact:

PAX API: Multiple commit of all quick reports (or other ways?)

Post by Elessar »

Hello everybody!

The Commit button commits data only in active sheet, so I'm asked to make a button to commit the entire book.

Firstly, maybe there is an option to make the Commit button commit the entire book (like the "Refresh" one)?

Secondly, I've made a VBA script to do this. The idea is to loop through all "tm1\\_X_R" named ranges to point the rows of each report book and to commit it

Code: Select all

Option Explicit
Option Compare Text

Sub CommitAll()
Dim nm As Name
Dim sFilters As String
Dim sRange As String
sFilters = "_R"
    
    For Each nm In ActiveWorkbook.Names
'Locate "tm1\\_X_R" named range 
        If InStr(nm.Name, sFilters) > 1 Then
            sRange = nm.Name
'Print where we are
            Debug.Print (sRange)
            Reporting.GetCurrentReport(Range(sRange)).Commit True
            Reporting.Wait
        End If
    Next nm
End Sub
This VBA throws error: "Run-time error '91': Object variable or With block varible not set". The most strange thing is that the error is thrown on different quick reports each time I relaunch excel.

Appreciate any help on this.
Or, if somebody has working VBA for this - please share.
Best regards, Alexander Dvoynev

TM1 and Data Science blog: 7th article - Development requirements.
User avatar
gtonkin
MVP
Posts: 1212
Joined: Thu May 06, 2010 3:03 pm
OLAP Product: TM1
Version: Latest and greatest
Excel Version: Office 365 64-bit
Location: JHB, South Africa
Contact:

Re: PAX API: Multiple commit of all quick reports (or other ways?)

Post by gtonkin »

Hi Alexander, Still very much a hack at this but you could try something like:

Code: Select all

Sub CommitQuickReports()

Dim oReport As Variant
Dim iReportCount As Integer
Dim iReportIndex As Integer

'Get number of reports in the book
iReportCount = Reporting.getreports().Count

For iReportIndex = 0 To iReportCount - 1

    Set oReport = Reporting.GetReports().Item(iReportIndex)
    Debug.Print oReport.Name
    oReport.Commit True
    Reporting.Wait
Next

End Sub
HTH
Adam
Posts: 106
Joined: Wed Apr 03, 2019 12:10 am
OLAP Product: IBM PA
Version: 2.0.9.x
Excel Version: Microsoft 365 x64

Re: PAX API: Multiple commit of all quick reports (or other ways?)

Post by Adam »

We've been using the below in production for quite a while. Note the lack of .Wait

Code: Select all

Sub CommitAllQuickReports()

    Dim currentNamedRange As Name
    Dim qrIDNumberWIP As String
    Dim qrIDNumber As Long
	
    For Each currentNamedRange In ActiveWorkbook.Names
		
		If currentNamedRange.Name Like "tm1\\_*_C" Then
						
			qrIDNumberWIP = Mid(currentNamedRange.Name, 7)
			qrIDNumberWIP = Mid(qrIDNumberWIP, 1, InStr(1, qrIDNumberWIP, "_") - 1)
			qrIDNumber = CLng(qrIDNumberWIP)
			Reporting.QuickReports.Get(qrIDNumber).Commit
			
		End If
		
	Next
	
End Sub
I've started blogging about TM1, check it out: www.havaslabs.com

Take care,
Adam
Wim Gielis
MVP
Posts: 3128
Joined: Mon Dec 29, 2008 6:26 pm
OLAP Product: TM1, Jedox
Version: PAL 2.0.9.18
Excel Version: Microsoft 365
Location: Brussels, Belgium
Contact:

Re: PAX API: Multiple commit of all quick reports (or other ways?)

Post by Wim Gielis »

Hi Adam, Alexander,

Just a small remark. Names have a Comment field, that is exposed through VBA. Maybe useful to use that one rather than the string manipulations. Not for speed but rather ease of use/maintainability/flexibility.

In general, this Comment field and also controls that expose a .Tag property, are useful candidates to store this kind of information.

Code: Select all

? Names("test_5_range").Comment
5
08.png
08.png (10.05 KiB) Viewed 4332 times
09.png
09.png (5.88 KiB) Viewed 4332 times
Best regards,

Wim Gielis

IBM Champion 2024
Excel Most Valuable Professional, 2011-2014
https://www.wimgielis.com ==> 121 TM1 articles and a lot of custom code
Newest blog article: Deleting elements quickly
User avatar
Elessar
Community Contributor
Posts: 358
Joined: Mon Nov 21, 2011 12:33 pm
OLAP Product: PA 2
Version: 2.0.9
Excel Version: 2016
Contact:

Re: PAX API: Multiple commit of all quick reports (or other ways?)

Post by Elessar »

Thanks George, Adam, Wim,

Geroge's variant looks the most elegant, and it works. And as Adam said, "Wait" is not needed. My final code is:

Code: Select all

Sub CommitAll()

Dim oReport As Variant
Dim iReportCount As Integer
Dim iReportIndex As Integer

'Get number of reports in the book
iReportCount = Reporting.GetReports().Count

For iReportIndex = 0 To iReportCount - 1
    Set oReport = Reporting.GetReports().Item(iReportIndex)
    oReport.Commit True
Next

End Sub
Best regards, Alexander Dvoynev

TM1 and Data Science blog: 7th article - Development requirements.
Post Reply