I received a protected excel file which only allows me to add values or select from a drop down list. The file has lots of different tabs, all in different format and questions.
I then unprotected the workbook to make my life easier (i.e. copy, paste, make notes etc)
using the code found here:
http://uknowit.uwgb.edu/page.php?id=28850
Now i am looking for a way to transfer all the values from the unprotected file back to the original file they sent me as I cannot submit an unprotected file. It is too many questions to do manually.
What is the best way to do this in excel 2013/VBA?
Thank you
It looks like you're wanting to do this on a sheet that previously had a password you didn't have access to. Also, it seems that you can't ask the worksheet creator to simply remove the password.
If both these are true, the best solution would be to save the modified sheet with the same name and send that sheet. From what I've seen, VBA and developer tools don't include a way to copy values to locked regions in a password-protected sheet, without unlocking that sheet:
ActiveSheet.Unprotect 'method to unlock current sheet, password may be required
ActiveSheet.Protect 'same to lock again
But, once a sheet is unlocked, you could loop through all cells in the region you want to copy from, and copy those values to the new sheet / workbook.
Please let us know if there's something else, or if something needs to be explained in more detail.
Related
I'm currently trying to construct a Workbook consisting of several Worksheets. However, the worksheets should be protected in a way so that they can't be opened unless the correct password is given. Ideally each worksheet should have its own password, i.e. if I were to click on say 'Sheet 2' I would have to enter a password in order to actually see the content of that sheet. I'm quite new to VBA and don't even know if this is even possible.
I have tried to solve the problem without VBA, but Excel does not have that kind of feature and only allows for the protection of cells, etc.
What i try to accomplish in Excel using VBA is to have a "original" workbook that is used to start with each time, adjusted and saved under a new name. This workbook, and all workbooks that come from it have a "client database" sheet where client data is automaticly copied in to (1 row per client, A:G). Whenever a original workbook is filled in the data is copied to the client database in that specific workbook, but then automaticly saved under another name.
Therefore i am looking for a code that opens the original workbook (done), compares the database sheet of the new file with the original and then updates the original with the new client data. (Best case they would update each other). What's important is that the whole row should be compared, as for instance one company can have different contacts.
Now my coding skills unfortunately aren't good enough to accomplish this, and i have browsed different topics to find a solution but wasn't able to find a solution that completely covers the problem (and is written simple enough for me to still understand).
Both sheets hold the same database structure and the tab is called "Klanten database".
If anyone would be able and willing to help that would be much appreciated!
I have already tried different codes from the forum, but they all focus on either columns or specific cells and are made to extract unique value's to a new list or just to highlight the differences. Or are to complicated for me to understand.. :X
Sub UpdateOriginal()
'Open original file to update
Workbooks.Open Sheets("Data inhoud").Range("J12").Value & "\original.xlsm"
'compare active database with original and update the both of them
Workbooks("original.xlsm").Close SaveChanges:=True
End Sub```
None have worked :(
I am wanting to put a notes section into a workbook, where notes can be added about a particular row in a worksheet. There will be lots of rows.
I want these notes to be uneditable once they have been written, so they can't be tampered with.
Previously I have done this by unprotecting, then protecting the worksheet to enter the note which is captured in VBA. However this workbook needs to be shared, which means you can't unprotect or protect a workbook either in VBA or manually.
Excel really isn't the right platform for this, as it's basically a small CRM, but unfortunately for the moment it's the only thing available and that can't change for now, so need to try and find a way to make it work, any idea's?
I have tried protecting the workbook with UserInterfaceOnly:= True, and that works great until the workbook is closed and re-opened then it fails and then can't unprotect or protect the workbook.
I have created an add-in that sends and retrieves data from a database in order for this data to be used by our analysts.
To prevent changes made to existing data points I want to lock the cells containing this data. Initially, I did this by locking the range of the data and protecting the workbook, since otherwise the locking does not work. However, protecting the workbook also removes/limits a lot of functionality for the end-user, such as creating graphs, the auto fill function, changing the format etc. Since these and other functionalities are needed for the end-user, I cannot protect the workbook. Still, I want to lock the cell containing the data points.
So my question is, is it possible to lock the cells in a dynamic range (I have macros detecting the correct end column and end row of the data points) without protecting the workbook? If so, how? If not, would it be possible to detect changes in the dynamic range and show a messagebox that changes are not allowed in this specific cell/range and revert back to the old value of the cell? If so, how?
I have seen a few posts asking a similar question, but these were either not answered or the answer was not satisfying for my case (e.g. a macro implemented in the VBA project of the workbook instead of the VBA project of the add-in).
Thanks in advance for your answer(s)!
Kind regards,
Robbert
Use
ActiveSheet.Cells.Locked=False
Then Lock your range which you don't want to be edited using:
Range("A1:A4").Cells.Locked=True
Then protect the sheet
ActiveSheet.Protect Contents:=True, DrawingObjects:=False
This will only protect the contents that are Locked and still allow you to change values in the rest of the sheet and insert/delete charts. You may have to change extra settings with Protect. More details can be found here
You don't have to protect the Workbook, only the Worksheet.
To protect/unprotect a sheet via VBA, use Worksheet-methods protect resp. unprotect (you can apply a password).
To prevent a range to be modified, you have to set it's locked-property to True and protect the sheet (all cells have the propery locked set by default).
Be aware that, if a Range is locked and the worksheet is protected, you cannot modifiy the Range via VBA. If you want to do so, use the unprotect method at the top of the code (but don't forget to protect the sheet again when you're done). As an alternative, you can call protect with parameter UserInterfaceOnly:=True, but unfortunately Excel doesn't save this property. So if you save an Excel file where a worksheet is protected with UserInterfaceOnly:=True and reopen it, the sheet is protected also for VBA.
I created an excel file about costing a metal desking frame, it consist of several worksheets, there is one specific worksheet - a template - where the user can enter data - but this sheet must not be duplicated as it would mess up the program, I protected the sheet but when pressing Ctrl key at the same time mouse dragging the sheet to the right it duplicated the sheet! while protect workbook completely freezes all worksheets! I want to prevent copy (duplication) only on one sheet (the template). How can I do this
also How do I prevent this specific sheet from being accidentally (or intentionally) deleted?
What you need to do is lock/unlock cells as required, and then enable worksheet protection. Passwords are optional but recommended to prevent accidental unlocking.
An important thing to note before going any further is that there is no fail-safe way to protect an Office document (against neither accidental nor intentional abuse or distribution). Even Office document passwords are easily defeated.
If you are this concerned about this data, you need to make sure that you are backing it up regularly, and automatically, and keep several versions of backups... (not just the most recent!)
Protecting a worksheet from changes
When you protect a worksheet, all cells are locked by default, which means that they cannot be edited. To enable cells to be edited while leaving only some cells locked, you can unlock all the cells and then lock only specific cells and ranges before you protect the worksheet. You can also enable specific users to edit specific ranges in a protected worksheet.
Try this an an example of the most basic form of protection:
Make a backup copy of your workbook before proceeding.
Click the Review tab, and then click Protect Sheet.
For now, just ignore the check boxes at the bottom of the Protect Sheet window. Choose a password and enter it where prompted. (Do not use a password that you use for other things.)
Click OK. Enter the password a second time and click OK again. The worksheet is now protected.
At this point, experiment to see if you are able to make the changes you were concerned about, such and duplicating cells with "Ctrl+Drag".
This is the default setting for protection. You'll notice that you can't use any of the cells at all, even for "legitimate" purposes, however this can be easily rectified too (with the password!).
Removing workbook protection
When you want to re-enable changes to the worksheet:
Click Unprotect Sheet on the Review tab.
Enter the password you previously set.
...I literally already forgot the password I had set, so the unlocking request was denied:
It's okay, I made a backup first and had it stored in a safe location.
(Actually, it was a test workbook, and even if it wasn't, I could bypass password protection on any Office document in under 5 minutes. Hence the earlier warning...)
Protecting only certain areas or certain activities
In most cases, it's not feasible to have the sheet 100% protected at all times, effectively rendering it "read-only" and non-interactive. (If it were necessary, you're better off to print the worksheet and hand out ultra-safe paper copies.)
Protection can be customized in numerous ways, the most common being unlocking only the sections that the user needs to be able to change.
In the example below, I protect the whole worksheet (since cells are set to "Locked" by default) with the exception of the 2 cells that require data entry.
Personally I like to always shade the unlocked cells a different color, so that it's obvious to the users which cells they can/can't use.
There are too many options to go into them all here, but below are links some of the many sites with more information and examples about Excel workbook ad worksheet security, protection, and other safety concerns:
Office.com : Protection and security in Excel
Office.com : Protect a worksheet (Excel)
Office.com : Lock or unlock specific areas of a protected worksheet
Newco.co : Excel 365: How to Protect Cells in a Shared Worksheet
MSDN : Password protect workbooks and worksheets (Video)