Somehow I’m unable. Since hours I google around and search through the BOB board, but I don’t find a solution which works completely.
Basically I let the user select a team name in a listbox. For each selected team exists a fix additional value. I would like to have that value now assigned to string in my macro, that I can filter a tab in BO based on that string.
Since my VBA knowlege is very limited I thought of applying a filter on a specific tab which will show me the team with its additional value. That works so far. However, how can I address this field and assign it to a string variable in VBA?
I tried with stuff like Application.CmdBars.Item(1).Controls.Item(1), …, since we use that in another report to copy a field over to an Excel application, but I can’t recode it to match it for my needs. I also tried stuff with ActiveReport.GeneralSectionStructure.Body.Item(1)… It seems I can count the bodies on a BO tab with latter apporach, but not get a specific field name like that…
Does anybody have a spontaneous idea how I could reach my goal? Any help highly appreciated!
Thanks alot!
Ok, getting closer to the solution. Found some code in the web and changed it to the code below. I receive like that the variable name in the table header. Unfortunately I would like the variable content from the table body…
However, at least a part of the “solution”:
Public mystring As String
Dim Doc As busobj.Document
Dim Rep As busobj.Report
Dim SecStruct As busobj.SectionStructure
Dim I As Integer
Dim boDocVar As busobj.DocumentVariable
Dim boBlock As busobj.BlockStructure
Set Doc = Application.ActiveDocument
Set Rep = Doc.ActiveReport
Set SecStruct = Rep.GeneralSectionStructure
For I = 1 To SecStruct.Body.Count
Set boBlock = SecStruct.Body(I)
Select Case boBlock.Type
Case boTable
Set boDocVar = boBlock.Pivot.Body(1)
mystring = boDocVar.Name
Hi, BO works only with DataProvider - not with representation (filters, etc). See my post 2 weeks ago:
With filters only you can save report to Excel whole document.
Sample:
Private Sub Document_AfterRefresh()
Dim Var, Var2 As DocumentVariable
Dim sprs As String
Dim i As Long
Dim uploadType As String
Dim savePath As String
savePath = ThisDocument.DocumentVariables("saveToPath").Formula
If (UCase(ThisDocument.DocumentVariables("saveTo_XLS_PDF_N").Formula) = "XLS") Then
uploadType = "XLS"
End If
If (UCase(ThisDocument.DocumentVariables("saveTo_XLS_PDF_N").Formula) = "PDF") Then
uploadType = "PDF"
End If
If (UCase(ThisDocument.DocumentVariables("saveTo_XLS_PDF_N").Formula) <> "XLS" And UCase(ThisDocument.DocumentVariables("saveTo_XLS_PDF_N").Formula) <> "PDF") Then
uploadType = "N"
End If
If (uploadType = "XLS" Or uploadType = "PDF") Then
If (Dir(savePath, vbDirectory) = "") Then
MkDir savePath
End If
End If
If (uploadType = "XLS" Or uploadType = "PDF") Then
Set Var = ThisDocument.DocumentVariables("Portfe&#316;a nosaukums")
If UBound(Var.Values(boUniqueValues)) > 0 Then
For i = 1 To UBound(Var.Values(boUniqueValues))
sprs = Var.Values(boUniqueValues)(i)
Call ThisDocument.Reports(1).AddComplexFilter("Portfe&#316;a nosaukums", "= <Portfe&#316;a nosaukums> = """ & sprs & """")
ThisDocument.Reports(1).ForceCompute
If (uploadType = "XLS") Then
ThisDocument.SaveAs (savePath & "\" & sprs & ".xls") 'Mid(sprs, 6, 8)
End If
If (uploadType = "PDF") Then
ThisDocument.ExportAsPDF (savePath & "\" & sprs & ".pdf") 'Mid(sprs, 6, 8)
End If
Call ThisDocument.Reports(1).AddComplexFilter("Portfe&#316;a nosaukums", "= <Portfe&#316;a nosaukums> = <Portfe&#316;a nosaukums>")
ThisDocument.Reports(1).ForceCompute
Next i
End If
End If
End Sub