Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Not applicable

Macro to add "Clear Field" actions to a Text Object

   Hi all -

I'm attempting to write a macro that will add a "Clear Field" action to a specified text object for every field that exists within a particular table in my qvw (the Calendar table in the below example).  The below code works in the following scenarios:

1. I create a new text object and run the macro.  The initial run of the macro works, however subsequent runs add only the first and last field in my table.

2. I add a message box to the code below to display k for each value of the index

3. I run this macro via an external program that opens the QVW, runs the macro, and then closes the QVW.

Does anyone have any thoughts on additional things to try?

sub ButtonActionsFields

set flds=ActiveDocument.GetFieldDescriptions


for i=0 to flds.count-1

set fld=flds.item(i)

if not fld.IsSystem then




  for j=lbound(tables) to ubound(tables)

   fldTables=fldTables & tables(j) & ";"


end if

if instr(fldtables,"Calendar") then



  call AddClearFieldAction2(fld.name)

end if


end sub

sub AddClearFieldAction2(field)

  set Button1= ActiveDocument.GetSheetObject("TX1001")

  set prop1 = Button1.GetProperties

  set actions1 = prop1.Layout.ActionItems


  k = actions1.count - 1


  'ActiveDocument.GetApplication.Sleep 2000

  actions1.Item(k).Type = 36


  actions1.Item(k).Parameters.Item(0).v = "[" & field & "]"

  Button1.SetProperties prop1

  set Button1 = nothing

  set prop1 = nothing

  set actions1 = nothing

  set k = nothing

end sub