Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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?
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.
I suggest that you post the entire macro code, rather than the part that works.
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?
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
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
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.