Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
sathishkumar_go
Partner - Specialist
Partner - Specialist

How to use macro for Change label Name in Table Box

Hi,

Can some one give me macro code , For changing label Name in Table Box.

Sathish

1 Solution

Accepted Solutions
Not applicable

Sub TableBox
set tb = ActiveDocument.GetSheetObject("TB01")
set tbp = tb.GetProperties
set cols = tbp.Layout.ColLayouts
cols.Item(0).Label.v = "New Name"
tb.SetProperties tbp
End Sub


This is for a TableBox with ID = TB01. This changes the first label. Modify the number in Item(x) to the column you want to change (it starts with 0). Cols is an array, so you can cycle through the list if you would like. Check the APIGuide for more information.

View solution in original post

6 Replies
Not applicable

Hi,

Does it have to be a macro that changes the label? Or can you use a variable instead?

Thanks

Nick

Not applicable

Sub TableBox
set tb = ActiveDocument.GetSheetObject("TB01")
set tbp = tb.GetProperties
set cols = tbp.Layout.ColLayouts
cols.Item(0).Label.v = "New Name"
tb.SetProperties tbp
End Sub


This is for a TableBox with ID = TB01. This changes the first label. Modify the number in Item(x) to the column you want to change (it starts with 0). Cols is an array, so you can cycle through the list if you would like. Check the APIGuide for more information.

sathishkumar_go
Partner - Specialist
Partner - Specialist
Author

Thanks Miller.

Its working fine

-Sathish

sathishkumar_go
Partner - Specialist
Partner - Specialist
Author

Hi Miller,

if i want to change chart straight table then this macro gives error. In straight table, How i pass dimension label name in macro???

-Sathish

Not applicable

The macro is a little different when working with a chart. For some reason, on a chart, the Dimension Label Attribute is called Title. Try this:

Sub Test
set chart = ActiveDocument.GetSheetObject("CH01")
set cp = chart.GetProperties
set dims = cp.Dimensions
dims(0).Title.v = "Test"
chart.SetProperties cp
End Sub


Similarly to the above, the dimensions are an array, so you will need to choose the right element or you can loop through them.

hugmarcel
Specialist
Specialist

Hi

If you have a table with all columns qualified, a common task in table charts is to set the column labels to unqualified names. So e.g. x.y becomes y. This macro does this for you:

Call UnqualifyAllTableColumnLables("TB01")

Sub UnqualifyAllTableColumnLables(theTable)
  Set tb = ActiveDocument.GetSheetObject(theTable)
  Set tbp = tb.GetProperties
  Set cols = tbp.Layout.ColLayouts
  For i = 0 to tb.GetColumnCount-1
    Set fld = tb.GetField(i)
    If (Len(cols.Item(i).Label.v) = 0) Then cols.Item(i).Label.v = Mid(fld.Name,Instrrev(fld.Name,".")+1,999)
  Next
  tb.SetProperties tbp
End Sub

Marcel