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
Related
I'm completly new at this and trouble is that I got to keep Office97 compatibility. My friends call me "Ctrl+C - Ctrl+V coder", so sorry if that's a stupid question.
I've got this timestamp event runing, but it can't put value in protected sheet. I can't turn off protection while file is shared. I found AllowEditRange VBA command, so i can put timestamp in the field, but can't protect it back. I can make workaround with hidden sheet, but it's not as tidy, as "re-protection".
ActiveSheet.Protection.AllowEditRanges.Item(1).Unprotect "Password"
Is there any way to make this line work just for 1 modification, but every time i call it? Or only for VBA modifications, and not user interface? Documentation leaves no hope. I've spent way to much time on looking it up on forums.
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.
Summary:
So I have a workbook that has been distributed and will need to be updated on occasion. After some research and investigation, I have opted for the workbook to import a networked .bas file (Visual Basic code module), execute the module's code to update said workbook and finally remove the module once completed.
Problem:
I was wondering if there might be any issues with this method, as it seems to work and be implemented too easily, when compared to an add-in for example.
My code is simple, in the workbook_open event I import and run the "update" module:
1) VBproject.vbcomponents.Import MyModule
2) Execute MyModules code
3) VBproject.vbcomponents.remove MyModule
(2) and (3) are completed in another subroutine, otherwise the module's methods aren't recognised after importing and can't be used.
Thanks in advance for any issues that might come of this.
If the question is too vague or open ended let me know and I'll remove it or alternatively I can provide further specifics.
Thanks in advance guys
The main issue I can think of is that for this to work, you need your users to accept to Trust access to the VBA project object model.
They might not want that, reasonably, or be forbidden to do that, because it involves some security risks.
Imagine someone succeeds to drop a malicious .bas file with the same name/place of yours. You need to take measures against that, and convince the users and especially the security admins...
(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.