Injecting custom Macros and trying to remove them before saving.

Add-in Express™ Support Service
That's what is more important than anything else

Injecting custom Macros and trying to remove them before saving.
 
MarcumLLP




Posts: 31
Joined: 2015-02-10
I have a xlsx file that when opened I can "inject" Macro code and have it executed. We do this because we have a internal web site that admins maintain custom VB code that gets executed and if they need to make a change to the VB code, we know when the workbook opens up again they will have the latest VB code. The problem is when they click save I need to remove the Macro that was injected so it can be continued to be saved as an xlsx. I tried hooking into the "WorkbookBeforeSave" event but that fires AFTER Excel displays a warning dialog to the user that they are trying to save an Excel spreedsheet with a Macro.

My question is what event can I hook into that would fire when the user clicks saves and before that warning dialog gets displayed so I can remove the VB code. (This is for Excel 2013 and up)

Thank you
Posted 25 Apr, 2017 15:36:16 Top
Andrei Smolin


Add-in Express team


Posts: 14106
Joined: 2006-05-11
Hello,

I'm sorry, I couldn't respond earlier as we were on holidays.

There is no such event. But you can intercept clicking the Save As/Save button itself. A step by step instruction is given in section How to intercept or disable a built-in Ribbon control, see https://www.add-in-express.com/docs/net-ribbon-tips.php#intercept-builtin-ribbon-control. The instruction requires specifying the IdMso property of the Ribbon command component(s), find details in section Referring to Built-in Ribbon Controls, see https://www.add-in-express.com/docs/net-ribbon-components.php#referring-built-in-ribbon-controls.

Also, you'll need to intercept pressing Ctrl+S and (probably) other keyboard shortcuts that cause saving the workbook. Use an ADXKeyboardShortcut component(s) to achieve this.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 26 Apr, 2017 03:22:33 Top
MarcumLLP




Posts: 31
Joined: 2015-02-10
Perfect, thank you!
Posted 26 Apr, 2017 08:11:30 Top
Andrei Smolin


Add-in Express team


Posts: 14106
Joined: 2006-05-11
Welcome!

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 26 Apr, 2017 08:29:15 Top
MarcumLLP




Posts: 31
Joined: 2015-02-10
Ok, I was just looking into your solution and the problem is the IdMso TabSave (File Save As) does not fire, event though my ActionTarget is set to Button.

IdMso "FileSave" works, any idea why "TabSave" doesnt work?

Thank you
Posted 26 Apr, 2017 09:15:11 Top
Andrei Smolin


Add-in Express team


Posts: 14106
Joined: 2006-05-11
IdMso="TabSave" denotes a tab, not a button! You can hide the tab, insert a custom one, and handle events of its controls. See also https://www.add-in-express.com/forum/read.php?FID=5&TID=11593 and https://www.add-in-express.com/forum/read.php?FID=5&TID=11440.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 27 Apr, 2017 04:19:27 Top