Qlik Community

Qlik DataMarket Discussions

Discussion Board for collaboration regarding Qlik DataMarket.

Not applicable

How can we change the background colour for many text boxes at a time?

Hi,

For the below app, can the colour for all the 6 text boxes be changed at a time.
text_box.JPG

Please let me know, if there is a way.

Thanks.. Barsha

Tags (1)
7 Replies

Re: How can we change the background colour for many text boxes at a time?

Yes, it's possible - the background color could be an expression which react on a selection or a variable like:

if(getfieldselections(ColorRange) = 'grey', rgb(190,190,190), blue())

- Marcus

raajaswin
Contributor III

Re: How can we change the background colour for many text boxes at a time?

Hi Marcus,

     If the text boxes are already created without any colour expression but by fixed colours. Whether it is possible to change colour for all at a time. Is there any macro for that??

Re: How can we change the background colour for many text boxes at a time?

You would need a routine which runs through all your sheets and objects within a loop and checked if they are (the right) textboxes and then change the properties. Have a look on those both examples from the APIGuide.qvw (in your install folder) how such routine could look like:

function Rand (Lo, Hi)

    Rand = Lo + Rnd() * (Hi - Lo + 1) - 0.5

end function

sub randpiv

rem  ** set random colors in all expression        **

rem  ** cells in all pivot tables on active sheet. **

Objects = ActiveDocument.ActiveSheet.GetSheetObjects

For i = lBound(Objects) To uBound(Objects)

   If Objects(i).GetObjectType = 10 Then   'pivot tables

      set Pivot = Objects(i)

      set y = Pivot.GetProperties

      set e = y.ExpressionVisuals

      for k = 0 to e.Count-1

         set f = e.Item (k)

      set v = f.CellVariations (0)

         v.FgColor.Col = RGB(Rand(0, 127), Rand (0, 127), Rand (0, 127))

         v.BgColor.Col = RGB(Rand(128,255), Rand (128,255), Rand(128,255))

         v.TotalFgColor.Col = RGB(Rand(0, 127), Rand(0,127), Rand(0,127))

         v.TotalBgColor.Col = RGB(Rand(128,255), Rand(128,255), Rand(128,255))

      next

      y.TableProperties.StyleNumber = -1

      Pivot.SetProperties (y)

    end if

next

end sub

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

set mytext = ActiveDocument.Sheets("Main").CreateTextObject

prop = mytext.GetProperties

prop.Layout.BkgColor.PrimaryCol.Col = RGB(88,143,254)

mytext.SetProperties prop

But you will need many textboxes that such a routine makes sense (unless you want to learn more about the qlikview macros - then it might be a good starting point).

- Marcus

raajaswin
Contributor III

Re: How can we change the background colour for many text boxes at a time?

Thank you marcus. I am looking into it

raajaswin
Contributor III

Re: How can we change the background colour for many text boxes at a time?

Hi Marcus,

    Where to get that API Guide. Can you please attach it please...

Re: How can we change the background colour for many text boxes at a time?

Within your qlikview installation you have a folder automation and there is these qvw - but you could find it within the community, too: APIguide.qvw

- Marcus

raajaswin
Contributor III

Re: How can we change the background colour for many text boxes at a time?

Thank you so much Marcus_Sommer I got it..

sub aswin() 

    for a= 0 to ActiveDocument.NoOfSheets - 1 

        set b=ActiveDocument.Sheets(a) 

        Textbx=b.GetTextObjects 

        for c=lbound(Textbx) to ubound(Textbx) 

             set Tobj=Textbx(c).GetProperties 

             Tobj.Layout.BkgColor.PrimaryCol.Col = RGB(255,255,255)

             Textbx(c).SetProperties Tobj 

        next 

    next 

end sub 

It is working now.. Tried my first Macro in qlikview. Thanks a lot

Community Browser