Excel - Removing a Worksheet Before "Enable Content" Disables Macro's - vba

I have a rather interesting issue in excel(Office 365 Version 1708) that seems to be affecting every file that contains Macros. If I place a untrusted XLSM file containing VBA Macro's in a untrusted location and open the file I'm greeted with the following message:
If I click "Enable Editing", I am able to edit the file but I also get the following message:
Sometime, if I delete a worksheet in the file BEFORE clicking "Enable Content"; content is not enabled. I am not able to run any VBA Macro's triggered by Custom Ribbon Events, and code in "Workbook_Open" does not trigger and does not run. To use any Macro's in the file, it needs to be closed and reopened.
Other times, I find that once you delete a worksheet, that the "Enable Content" button disappears, and again the file has to be closed/reopened to access any Macro's.
Is this intended behavior? It's very strange... Is there any way to modify this behavior to allow VBA Macro's to run after the user clicks "Enable Content", and to persist this message after the user delete's a worksheet?

Related

Excel Macro - disabling "file now available for editing" msg

How do you disable the pop up message:
File now available for editing.
in Excel?
I couldnt do it in my python code so I am trying to see if I can do it within Excel macro. Do I apply the macro to the master copy, or the one I am opening up as read only?

Macro Button protected in protected worksheet

I am trying to run a macro which creates a pdf which work fine. When the excel file gets signed, the excel file gets automatically protected.
Problem: I have a button on the worksheet which needs to be pressed to create the pdf documnet. However this can not be done because the button has also got protected and cant be press. Is there anyway around this?
However if i try save the excel file as manaully as pdf it works.
Points to bear in mind
If the worksheet gets unprotected the signatures get removed.
Small around that will not delete the signatures
If the excel sheet is saved as a different name the signatures remain.
So if i am able to get the button to work . The workbook could be saved as different name ( in macro), and then save as pdf which will contain signatures.
Right click on the button and click on Format Control; go to the Protection Tab and untick Locked checkbox. It will then still be available when the sheet is Protected.

Resume Opening Workbook After Addin Interrupts

I've written an Excel addin that periodically checks a remote repository for data updates, including a check when the addin loads at Excel start up (during the addin's Workbook_Open event). If new respository data is detected, the addin asks the user for permission to proceed with the update. If the user clicks "yes", the addin successfully updates itself and everything is happy... except...
If Excel is not already running and the user selects an Excel file to open (e.g. via double-click in Windows), this sequence of events occurs and everything works, but the user-requested file opening is interrupted and not re-engaged. The Excel app is running, but with no workbook loaded (the workbook area is an empty frame).
I believe I have two options, neither of which I know how to accomplish:
Prevent the addin from completing its update check until the user-selected file has completed its open sequence and is fully loaded, or
Allow the addin to update itself and then somehow re-engage the user-selected file to complete the file open/load.
I have not been able to discover the filename/path of the user-requested file, so my addin isn't able to direct that file to be loaded.
My current workaround is a MsgBox telling the user to close Excel and re-open the selected file. Ideally, the addin update should occur and the original action should complete without requiring user intervention.
(Building on Option 1, I could start a delay timer for the addin to check for updates XX number of seconds after Excel starts, but this seems kludgy to me.)
Any guidance or ideas are appreciated. My interwebz searches aren't hitting the right combination of keywords for the exact scenario.
Instead of opening the new addin update file immediately you can use OnTime to delay it which should allow the other file to open successfully. See here: Process for updating Excel add-in?
In the answer you'll also see a reference to this package here which does everything you need. Autoupdates are hard so I would recommend going with someone else's solution.
http://www.decisionmodels.com/downloads.htm#addload
(Scroll down to Add-In Loader Version 2)

How to check if code that is run belongs to active sheet

I have written some code for an excel spreadsheet. This sub has been added to the ribbon using the standard customizations found in File -> Options -> Customize Ribbon. What is funny though, is that the customization will run the Sub on the EXACT EXCEL FILE that the Sub is written in, i.e. the original.
My users copy the excel file and make adjustments and then run the sub (by clicking the customized button in the ribbon), which then opens the ORIGINAL template file and runs the code. This actually works fine - and I like it because it runs the TEMPLATE code on the ACTIVE sheet. But the only problem is it is also OPENING the original template file. How do I get it to close? Remember it is not the ActiveSheet anymore.
One possible answer is to check if the template is open, then close it (using a static reference), but I would prefer something a little more elegant than that.
You should be able to find the template/original using ThisWorkbook.
Also, if you deliver your workbook's code as a .xlam instead of .xlsm, it will be opened, but there won't be a window for it, so users won't see it.
Not sure if you're using this already, but you might also want to use "for this workbook only" when adding ribbon buttons for a .xlam . (Delivering as .xlam allows you to install buttons from a workbook into the ribbon, without relying on file path and without needing your users to also install buttons (they install .xlam instead).)

Excel - "File Not Found: VBA6.DLL"

I have an Excel 2007 Sheet with Macros. When I click on a button, it immediately pops up an error "File Not Found: VBA6.DLL"
Problem is, I have been using this sheet forever, and never seen this problem before. I did make some very very minor changes to the Macro code.
And, I have 2 other sheets with identical macro code which I made the same changes to. And those two sheets run fine.
Any ideas?
In this order:
Check your references (Alt+F11, Tools-References) to see if any are marked MISSING and make sure that Visual Basic for Applicatiions is checked.
Check the directory C:\WINDOWS\system32 for VBA6.dll
You may need to register VBA6.dll (Start->Run)
Regsvr32.EXE "C:\WINDOWS\system32\VBA6.dll"
I had the same problem with a shared file. The fix was as follows:
Un-share the file
Copy all macros; sheets, this workbook, modules and saved them in a text format.
Save the .xlsm as a .xlsx file
Save back to .xlxm file
Paste all macros back in
Reset shortcut keys and descriptions in macro options
Re-share the file
This worked without having to go to IT and get someone with administrative credentials to fix it.