Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Run macro on conditional expression?

Hi all!

I want a macro to be run when a certain condition is fulfilled.

Like: If "Count(DISTINCT Field1)<10" then run the macro.

Is there anyway to do this? Can't see how this can be done by using triggers/actions.

Br

Peter

1 Solution

Accepted Solutions
Not applicable
Author

Hi Peter,

Go to

Document Properties Tab--> Triggers Tab--> Document Event Trigger --> Click On Any  Select --> Add Actions --> External --> Run Macro -->

If(Count(Distinct Field1)<10,'Macro')

May be this might helps you.

Regards,

Satish.A



View solution in original post

7 Replies
m_woolf
Master II
Master II

Maybe set a variable to =Count(DISTINCT Field1)

and then use the Variable Event OnChange action?

jagannalla
Partner - Specialist III
Partner - Specialist III

Hello,

Use this code,

Button ->action -> External -> Run macro -> in macro name give the below code. "Macro" is the name of the Macro Code


=If(Count(DISTINCT date)<10,'Macro')

My macro code is:

Sub Macro

    ActiveDocument.GetSheetObject("LB05").SelectAll

End Sub

Cheers!

Hope it helps you.

Not applicable
Author

The Variable Event OnChange action mean that you have to edit the variable expression to execute the action. It doesn't run due to the change in the calculated result in the variable (Count DISTINCT). So that's not the solution, unless I missunderstood.

Thanks

Not applicable
Author

Ok, but this mean you still have to click the button to execute the macro. What I'm looking for is execute a macro whenever the number of distinct values in a certain field is less than 10, due to some selections made in other fields, without having to click a button.

Thanks

Not applicable
Author

Hi Peter,

Go to

Document Properties Tab--> Triggers Tab--> Document Event Trigger --> Click On Any  Select --> Add Actions --> External --> Run Macro -->

If(Count(Distinct Field1)<10,'Macro')

May be this might helps you.

Regards,

Satish.A



jagannalla
Partner - Specialist III
Partner - Specialist III

Ok take one global variable with name vCount and give expression as =Count(DISTINCT Field1). Now create one empty varible with name vCheck.

- Document properties -> Triggers Tab -> Document event triggers -> OnAnySelect ->Actions -> Add -> External -> RunMacro -> macro name Assign

And paste in edit module below code:

Sub Assign

    Set vCount=ActiveDocument.Variables("vCount")

    Set vCheck=ActiveDocument.Variables("vCheck")

    vCheck.SetContent vCount.GetContent.String,true

    If vCheck.GetContent.String < 2 then

        Call(RunMacroCode)

    End If

End Sub

Sub RunMacroCode

           ' Here give ur code

   

End Sub

Cheers!

Hope it helps you.

Not applicable
Author

Thank you very much!

Regards Peter

Edit: Just realised this won't work when you toggle Back and Forward between a selection with less and more than ten values.

However, thanks anyway.

Edit again: Won't work with bookmarks either.

And worst of all, the macro (SQL connection) won't work at all in AJAX