Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Change object fonts by action


Hi All,

I have to provide a report with the possibility to switch all object's font and font size by a button.

I thought of using some variables - and an related action, unfortunately, it does not seem to be possible to use variables for the font.

Does anyone of you got an idea how to provide such functionality?

Thank you !

6 Replies
Clever_Anjos
Employee
Employee

Using macros, you can do what you want

I´ve extracted the code below from APIguide.qvw

rem  ** set random fonts modifications 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.SizeMod = Rnd() * 5 - 2 - 0.5

        v.StyleMod = Rnd() * 8 - 0.5          

        v.TotalSizeMod = Rnd() * 5 - 2 - 0.5

        v.TotalStyleMod = Rnd() * 8 - 0.5          

      next

      y.TableProperties.StyleNumber = -1  'set as custom style

      Pivot.SetProperties (y)

    end if

next

Not applicable
Author

Thanks Anjos for the hint

Anyway, I found this one in the APIGuide, which works fine:

(Class SheetObject, Member SetFont)

rem ** increase fontsize for all objects on active sheet by 1 point **

set sh = ActiveDocument.ActiveSheet

for i = 0 to sh.NoOfSheetObjects-1

    set obj = sh.SheetObjects(i)

    fnt = obj.GetFrameDef.Font

    fnt.PointSize1000 = fnt.PointSize1000 + 1000

    obj.SetFont fnt

next

unfortunately, it does not work for Objects placed in a container - any hint for that?

rustyfishbones
Master II
Master II

here is a simpler version and it works

SUB Font()

set sp = ActiveDocument.ActiveSheet.GetProperties

set sfont = sp.SheetFont

sfont.FontName = "Calibri"

sfont.Bold = false

sfont.Italic = false

sfont.Underline = false

sfont.PointSize1000 = 12000

ActiveDocument.ActiveSheet.SetFont sfont

END SUB

Clever_Anjos
Employee
Employee

Trick: create an empty tab and link your objects that are inside of your container there.

So run the macro into that sheet. It may work

Not applicable
Author


Hi Alan,

thanks for that simpler version!

Works fine - but not for contained objects 

(but i will use this for general and guess about a "container solution")

Not applicable
Author

Hi Anjos,

unfortunately the application has arround 180 objects (100 in containers) - i guess this would be a little bit too messy

but i still think it is possible to get the containeredobjects.

I found the Member ContaineredObjects in API Guide but do not have an idea how to use this for the formatting.