I've come up against a problem I can't think my way around so was hoping you guys could help.
We use Excel 2007 at work and I created a macro that validates data. Once the data has been validated with no errors, the macro makes available a button which when clicked calls a macro to copy the validated data to a new workbook.
My organisation uses a document management system called TRIM. TRIM has a COM add-in for MS Office that takes care of the saving so when the save button is clicked or the save/save-as menu item is selected, the add-in launches TRIM's save dialog and not the usual windows/office dialog. This save dialog does not give you the option to save the file as a particular type so will just automatically save the file into TRIM as whatever type the document was created as.
After help I've previously received from Norie, the way the "copy data" macro works is as follows: A new workbook is created; a hidden sheet with code already in the code module for that sheet is copied over to the new workbook; the data that has just been successfully validated is then copied and pasted into that new sheet in the new workbook. The result is a new workbook containing a sheet of validated data and a macro in the code module for that sheet. Which has been working well for me since I created it last year.
The time is coming now to roll this out to my colleagues to use but it has occurred to me that because I write macros all day long, I have changed the Save options in Excel Options to automatically create new documents as macro enabled.
Save Options.png
This means that the TRIM add-in automatically saves the new document as an Excel Macro-Enabled Workbook (*.xlsm) document. My colleagues however will have theirs setup as the standard Excel Workbook (*.xlsx) which means when they try to save, the TRIM add-in will automatically save it as those file types which will throw up warnings and prevent the save because that extension cannot include macros (or more accurately, it just saves it without the warnings and the result is the code is stripped out)
I had considered working out some kind of Workbook_BeforeSave code to capture the user's save event but the problem with that approach is the same as the problem that gets mentioned in the post I linked to above in that I'll need to insert code into the new workbook. So I considered forcing a save in the same macro that copies the data as soon as the data is copied with something like this:But it turns out that the TRIM add-in only intercepts UI initiated save commands and so a VBA initiated save command actually launches the usual Windows/Office save dialog which is no use as you can't save to TRIM from there.![]()
TheFileName = "Example.xlsm" wBook.SaveAs TheFileName, xlOpenXMLWorkbookMacroEnabled
Can anybody think of a way around this? Like can I use VBA to tell Excel to save a file but make Excel "think" the command came from a UI selection? Or is there some way for me to view the code of a COM add-in so I can find out what procedure I'd need to call within that add-in?
My posts always seem to be very long so apologies, but I'm a great believer in explaining a situation properly. That said, if there's more I can add, please let me know.
Thanks for any help you can give me.
Bookmarks