Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
swati_rastogi27
Creator
Creator

Multiple macros execution on single button click

Hi all ,

Can we not execute 2 macros on a single button click.

I have written below code to capture screenshot of a particular sheet object:

public function ExportImage

  ActiveDocument.GetApplication.WaitForIdle

   ActiveDocument.GetSheetByID("SH06").Activate

    vFolder = ActiveDocument.GetVariable("vExportFolder").GetContent().String

    ActiveDocument.GetApplication.WaitForIdle

    set obj = ActiveDocument.GetSheetObject("CH167")

  ActiveDocument.GetApplication.WaitForIdle

   fileName = "Report_" & replace(replace(replace(date() & "_" & time(), "/", ""), ".", ""), ":", "") & ".png"

   ActiveDocument.GetApplication.WaitForIdle

   obj.ExportBitmapToFile vFolder & fileName

  end function

If I write another macro to similarly capture screenshot of another object, now nothing happens and the Edit module pops up.

Where am I going wrong?

1 Solution

Accepted Solutions
Peter_Cammaert
Partner - Champion III
Partner - Champion III

Macro objects are defined for your entire document, not just for a single button or object. If you change a macro name by editing it in the actions dialog of one button, it will have changed for all actions that rely on this macro.

View solution in original post

5 Replies
jonathandienst
Partner - Champion III
Partner - Champion III

I suggest that you post the entire macro code, rather than the part that works.

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
swati_rastogi27
Creator
Creator
Author

Also , I tried to create 2 separate buttons to capture screenshot, but when I change the code in one button macro, the other one also gets affected.

How can I avoid this?

tamilarasu
Champion
Champion

Hi,

Try this,

Public function ExportImage

  ActiveDocument.GetApplication.WaitForIdle

   ActiveDocument.GetSheetByID("SH06").Activate

    vFolder = ActiveDocument.GetVariable("vExportFolder").GetContent().String

    ActiveDocument.GetApplication.WaitForIdle

    set obj = ActiveDocument.GetSheetObject("CH167")

  ActiveDocument.GetApplication.WaitForIdle

   fileName = "Report_" & replace(replace(replace(date() & "_" & time(), "/", ""), ".", ""), ":", "") & ".png"

   ActiveDocument.GetApplication.WaitForIdle

   obj.ExportBitmapToFile vFolder & fileName


'**************************************************************

Second export chart ID

  set obj = ActiveDocument.GetSheetObject("CH01")

  ActiveDocument.GetApplication.WaitForIdle

   fileName = "Report_" & replace(replace(replace(date() & "_" & time()+1, "/", ""), ".", ""), ":", "") & ".png"

   obj.ExportBitmapToFile vFolder & fileName

'**************************************************************

  end function

tamilarasu
Champion
Champion

Hi

First button Macro:

Change the function name as ExportImage1.

public function ExportImage1

  ActiveDocument.GetApplication.WaitForIdle

  ActiveDocument.GetSheetByID("SH06").Activate

    vFolder = ActiveDocument.GetVariable("vExportFolder").GetContent().String

    ActiveDocument.GetApplication.WaitForIdle

    set obj = ActiveDocument.GetSheetObject("CH167")

  ActiveDocument.GetApplication.WaitForIdle

  fileName = "Report_" & replace(replace(replace(date() & "_" & time(), "/", ""), ".", ""), ":", "") & ".png"

  ActiveDocument.GetApplication.WaitForIdle

  obj.ExportBitmapToFile vFolder & fileName

  end function

***************************************

Second button Macro:

Change the function name as ExportImage2 and chart ID as per your requirement..

public function ExportImage2

  ActiveDocument.GetApplication.WaitForIdle

  ActiveDocument.GetSheetByID("SH06").Activate

    vFolder = ActiveDocument.GetVariable("vExportFolder").GetContent().String

    ActiveDocument.GetApplication.WaitForIdle

    set obj = ActiveDocument.GetSheetObject("CH01") 'your second chart ID

  ActiveDocument.GetApplication.WaitForIdle

  fileName = "Report_" & replace(replace(replace(date() & "_" & time(), "/", ""), ".", ""), ":", "") & ".png"

  ActiveDocument.GetApplication.WaitForIdle

  obj.ExportBitmapToFile vFolder & fileName

  end function

Peter_Cammaert
Partner - Champion III
Partner - Champion III

Macro objects are defined for your entire document, not just for a single button or object. If you change a macro name by editing it in the actions dialog of one button, it will have changed for all actions that rely on this macro.