I password protected my VBA Editor with:
Tools > VBAProject Properties > Protection
Clicked "Lock project for viewing"
Added a password.
What I need to have happen is that when this password prompt is accepted, It needs to run a Sub I've already written.
The answer I'm looking for and can't find in the three books on my desk is:
Is this action a Workbook Event? Or something else? And what syntax can make this happen.
Thanks!
Potential solution from MSDN:
https://msdn.microsoft.com/en-us/library/office/aa165442(v=office.10).aspx
This won't work for for what I'm trying to do. I wrote a script that asks for a key delivered weekly to authorized users via another program. What I wanted is a Sub to run which deletes all of my sensitive data if the user enters an incorrect password while attempting to get to the code.
Looks like this is not possible in Excel VBA... I'll keep learning and searching for a way to do this. If I do I will revisit this post.
Related
(Questions with an answer of NO are still useful; they're just not the solution to the problem. Answers say, no, there is no built-in, you have to implement the dialog for yourself...)
In VBA, (ms-word, or ms-excel, but seems like a generic operation) is there any way to simply a provide a collection to a built in dialog in order to prompt the user to select a value from a list of values?
I can't believe there's not a built in method to do this, it seems like a such a generic operation that could be coded once and everybody would re-use it. I can certainly hand code it, but why bother if it's already in the vba libraries someplace.
I've searched for a solution, but it does appear that the standard answer is to hand code it.
My aproach would be to create a Form, add a ListBox, Ok, Cancel and the ShowModal property.
To use it first set the ListBox RowSource according to what you need:
https://msdn.microsoft.com/en-us/library/office/ff196460.aspx
Then make it visible, manage Ok/Cancel and then use the ItemsSelect property (multiselect is possible):
https://msdn.microsoft.com/en-us/library/office/ff823015.aspx
Yup, no such thing.
Hand-code it, and keep it as part of your VBA "toolbox" - make yourself an add-in that other VBA projects can reference, so you can reuse the code without having to rewrite it every time.
Then export the code modules from your host document, upload them to a GitHub repository, and share your solution with the world so the next person looking for it doesn't need to implement it from scratch again.
The VBA standard library is rather limited, and beyond MsgBox there isn't much available in terms of built-in UI. That's just how it is.
I was wondering if anyone could help me to disable the Advanced Filter option in Excel 2013.
I have used the following to disable all other data ribbon options:
.Protect UserInterfaceOnly:=True
But advanced filter is still able to be selected. With this they can unfilter the data.
The following code used to work in older versions of Excel but I cannot seem to get it to work for Excel 2013:
Application.CommandBars("Worksheet Menu Bar").Controls _
("&Data").Controls("&Filter").Controls("&Advanced Filter...").Enabled = False
If anyone could help me out with this or point me in the right direction then it would be appreciated.
Thanks guys.
Solution Suggested
The approach will be hiding the button from the user interface: the advantage on this solution is that the code is not in VBA (entirely) so, is not that easy for the user to modify it (or know what is going on backstage).
Answer Explanation/Next steps
It's really a deep answer with many steps involved in it so, I'll just post guidance and some useful links, that way you may research about it first.
1. Download Custom UI Editor for Microsoft Office: this helps to modify the user interface for the document.
2. Look for tutorials; start to code there with something basic like adding a tab and a button, (this is a good one)
3. Back to Excel, look for life cycle and custom events, this is a good place to start
4. You'll need to catch the event when the Ribbon is loaded; in that time, you'd need to disable the button, these links (1,2) are useful to show the steps and some example workbooks for it.
5. Locate the ID for the button and disable it (Hint: The idMSO = AdvancedFilterDialog, if you 've followed the previous steps, it will make sense here-).
Further information/Answer Disclaimer
Excel is not a software that can handle security deeply; if you are trying to restrict the user somehow in the original file, you should try other approaches -IG: a copy of a workbook for reference only, while the master one is saved in a sharepoint only modifiable by people authorized for it-.
While FAQ in S.O is strict about referencing to other sites without using a proper reference for it, this is a deep step solution that would take pages to explain even a random example; appealing to the guiding topic, this answer should be ok.
I am creating a MIS (Management Information System) in Excel, and am required to make use of 'What-If Analysis'.
I'm in the process of adding various scenarios to the Scenario Manager, and to make it more user-friendly I am displaying the whole system in full-screen. This however means that the user won't be able to open the Scenario Manager.
I cannot simply assign each scenario to a button/drop-down list as the user needs to have the ability to edit each scenario. This therefore means that I'll need to program a VBA macro to launch the Scenario Manager.
This, however, has presented a problem: it doesn't seem possible to launch the Scenario Manager using VBA!
I've tried searching for it, but however all pages I've visited contain code for launching an individual scenario with the following:
ActiveSheet.Scenarios("[scenario name here]").Show
However there doesn't seem to be anything to launch the actual scenario manager:
I've also attempted to record a macro to do this, but the macro itself is empty:
Sub whatIfManager()
'
' whatIfManager Macro
'
' Keyboard Shortcut: Ctrl+Shift+W
'
End Sub
I tried ActiveSheet.Scenarios().Show on the off-chance that would work, but it doesn't (no method with that name).
Is it possible at all to launch the what-if scenario manager using VBA? If so, how?
The method you are looking for is in the Application object, specifically Application.Dialogs. Something like this will do it:
Application.Dialogs(xlDialogScenarioCells).Show
The enumeration value determines the dialog to show. The full list of dialogs is available here.
Hello everyone and greetings from Germany!
After searching for quite some time I am at my wits' end and I hope someone can help me.
I try to describe my problem as clear and briefly as possible:
I am building a MS Excel 2010 Workbook that includes several (90+) external connections to SharePoint 2013 Lists & Libraries.
These connections were created by SharePoint's integrated "Export to Excel" function (in the List/Library-Ribbon) and the connection-files were then exported to another SP farm.
(The first "source"-SP-Farm is from the customer, the second is our own intranet)
I have to refresh these connections once per day via an automated macro.
A timer-job will open the workbook at night and execute the "RefreshAllConnections"-macro,
that does a little bit more than just refreshing (such as writing the refresh date and time).
So no user is present when this happens.
And this is where my problem is:
From time to time some of those connections cannot be refreshed.
Excel displays an alert saying (translated from german):
"the following data range could not be updated: owssvr (...)
Do you wish to continue the update?
(OK) / (Cancel)
What I found out so far:
1) It's always the Library that is the problem
2) It's rather random which Library won't update and when
3) The problem fixes itself after some time (that's why I'm guessing this has something to do with the library being used/modified by someone else)
4) While a library is refusing to update, using "Export to Excel" function again will prompt an error once the new worksheet is created and the data is supposed to be filled in
Now here are the odds:
1) The alert always uses the "old/original" connection name that was already changed by me.
2) When I press OK the macro just continues in the next line, no error is thrown whatsoever
3) If I press cancel an Error 1004 occurs (which I can at least catch, so that would be okay).
And here are the probs:
Since this is happening automatically at night, there is no user sitting near by to answer these alerts. So:
1) The macro must automatically answer these alerts with "Cancel" IF they pop-up (and I have NO idea how to do that!)
2) I disable them via "Application.displayAlerts = false
HOWEVER: this will automatically answer them with the default answer, which is "OK".
This however is not throwing an error I could catch, so my macro won't now whether the update acutally worked or not.
Well that's about it. Sorry for the long post and thanks for reading.
Hopefully someone of you has an idea.
EDIT:
Could it be that the automatically by SharePoint generated connections are the problem?
(How) can I build them myself?
Well. I solved it myself.
The answer was stupidly simple:
Instead of refreshing the Connection, I now refresh the corresponding QueryTable via "ActiveSheet.ListObjects(1).QueryTable.Refresh"
If the Connection is not responding, an error is thrown that I can now catch properly.
Ugh, finally!
When I use (some code here).copy destination:=(some code there). It will still prompt for protection issues on cells. Basically it just won't let my code runs.
The status UserInterfaceOnly:=TRUEis unfortunately not stored in the file - therefore, if you reopen the file, it will be fully protected. Either use the Workbook_Open event to reapply this protection status - or unprotect and then reprotect the worksheet in your VBA code directly.
See Ozgrid for further details!
I posted one approach to solving this here: https://stackoverflow.com/a/69730040/13307304
Like Peter Albert mentioned, the password itself should not be hardcoded