Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
See why IDC MarketScape names Qlik a 2025 Leader! Read more
cancel
Showing results for 
Search instead for 
Did you mean: 
OmarBenSalem

Alert message when Macro fails

Hi community,

When we execute a macro and it fails,the per default thing that happens is that the macro script is shown.

My question now, is there a way, instead of this behaviour, a Message Box is shown (an alert) saying that the macro failed to execute? or/AND an email is sent saying that the MACRO FAILED TO EXECUTE?

Thank you a lot !

1 Solution

Accepted Solutions
srivastalans
Partner - Contributor III
Partner - Contributor III

Hi,

Create a dummy variable as vA in Variable Overview and go to Document Properties --> Triggers --> OnPostReload --> add actions (b4 Run Macro) --> Set Variable --> Variable = vA , Value = 1

Below Set Variable vA, add action Run Macro --> Macro Name = Check

Try this code in macro (Tools --> Edit Module),

Sub Check

If (ActiveDocument.Evaluate("=$(vA)"))=1 then

'Your Code

'

'

'

Set Var1 = ActiveDocument.Variables("vA")

    Var1.SetContent "0",true

  

else

Msgbox("Macro Failed")

End If

   

end sub

View solution in original post

8 Replies
HirisH_V7
Master
Master

Hi ,

You want to sent email means through QMC or just reload. As QMC will not execute macros.

Have a look into this,

Re: QVW to create bat file which contain the copy command for all the QVD's used in the QVW. Help on...

HTH,

Hirish

HirisH
srivastalans
Partner - Contributor III
Partner - Contributor III

Hi,

Create a dummy variable as vA in Variable Overview and go to Document Properties --> Triggers --> OnPostReload --> add actions (b4 Run Macro) --> Set Variable --> Variable = vA , Value = 1

Below Set Variable vA, add action Run Macro --> Macro Name = Check

Try this code in macro (Tools --> Edit Module),

Sub Check

If (ActiveDocument.Evaluate("=$(vA)"))=1 then

'Your Code

'

'

'

Set Var1 = ActiveDocument.Variables("vA")

    Var1.SetContent "0",true

  

else

Msgbox("Macro Failed")

End If

   

end sub

OmarBenSalem
Author

if I have this;

sub Distribute

bla bla

end sub


and then add :


Sub Check

If (ActiveDocument.Evaluate("=$(vA)"))=1 then


'//here is my code

sub Distribute

bla bla

end sub


'//////


Set Var1 = ActiveDocument.Variables("vA")

    Var1.SetContent "0",true

 

else

Msgbox("Macro Failed")

End If

 

end sub



=> I have a syntax error !

How to surround my sub with the check sub?

srivastalans
Partner - Contributor III
Partner - Contributor III

Hi Omar,

   Add your code without including Sub Distribute and end sub..

OmarBenSalem
Author

That's really good ! and what if with the alert, I want to send an email just for me with the object : macro failure and a message: the macro has failed?

srivastalans
Partner - Contributor III
Partner - Contributor III

Hi Omar,

     I want to work on that error message as mail to User.

Regards,

Sri

srivastalans
Partner - Contributor III
Partner - Contributor III

Check this Omar,

Better in else script you can add this,

https://community.qlik.com/thread/69476

OmarBenSalem
Author

Great !