Is there a way to add an unprotected range with the google sheets api? - google-sheets-api

I see in the documentation that you can add protected ranges and remove those that you add. But is there a way to add an unprotected range?
I need to unprotect 3 cells in a protected sheet and not seeing any ways to do so.
If I use the get api, I can see in the response there is a protected range for said sheet, with an array of unprotected ranges. Is there a request to add to that array of unprotected ranges?
The documentation has no leads.
Thanks

Related

Workbook Allow Paste Special Values Only

I'm in need of some expert help, i have a workbook where i need to only allow Paste Special Values. This particular workbook as special formatting ect. that I don't want overwritten when a user does a standard paste vs. paste values. I tired some VBA but couldn't get that to work quite right, and also tried the custom ui route and was able to disable the entire idMso PasteGalleryMini but i need to keep these paste special values here.
Any help or suggestions is appreciated
There are (at least) a couple of ways you could try.
Have 2 sheets in your workbook, one is for user-entered data, and the other is for formatted display of data. The formatted display sheet is protected so cannot be amended by the user - it picks up the data from the user-entered sheet which is not protected but formatting is less important. So the user cannot interfere with the formatting or layout of the protected sheet.
This approach may require quite a bit of code to ensure validation and management of data between the input sheet and the display sheet, for example if you expect the user to insert rows etc., but if your requirement is simple then it's quite acheiveable.
Allow the user to paste with formatting but then reset the formatting after the paste has been done. I have found a good approach is to use your own custom styles, where the style can define all aspects of the appearance of the cells. The user can paste data into the sheet, then when finished have a macro trigger to run code that cleans up all the formatting by setting the styles of the different areas of your sheet to the appropriate custom styles. This approach is very effective, specially if you might want to alter the styles later - you may be able just to change the style definition and don't have to change the code. You can make this easier if you have a separate sheet on which all your custom styles are listed with their names and example values in cells which are formatted with that named style. The custom styles sheet can be hidden/protected to avoid users making changes.

Give macro access to protected sheets

I have an application built in MS Excel using VBA. I originally protected some worksheets and the VBA project by password. My users can only input and use drop downs on specific cells in specific sheets. To let my VBA modify the protected sheets I had to unprotect the sheets and then reprotect them using the password.
The requirement of the project has now changed and now requires me not to have a hard coded string for the password in the code to protect and unprotect the sheets.
A code sample of what is going on in my VBA code is the following.
Worksheets("Loading").Unprotect ("****")
[Functional Code]
Worksheets("Loading").Protect ("****")
Considering that I have to have the password to gain access to the VBA project is there a way to allow the project to interact with protected sheets as if they were not protected?
If no. Is there another method of preventing user interaction with a sheet while not inhibiting VBA interaction ( Very hidden would not work for the user still needs to see the sheet ).
Side note: This needs to prevent a normal person with minimal technical skills from altering the sheets in ways that they shouldn't
On an unprotected worksheet use,
Worksheets("Loading").Protect Password:=****, UserInterfaceOnly:=True
See Worksheet.Protect method for full details. Once it has been set with this extra parameter and the workbook has been saved, the protection will be bypassed by any VBA code but remain in place for user interaction.

VBA : Protect whole sheet and leave range unprotected

I'm working on Excel and would like to know if there is a way, within a script, to protect a sheet entirely but leave a certain range totally unprotected (the range here is ("B2", "C32")
In Format, unlock the cells you want to allow updating (they are all locked by default), then activate sheet protection, with or without password. For VBA learning, use the recorder.

How to edit, hide and protect a single sheet whilst also keeping other sheets hidden and protected

Thanks for taking a look at this question, I can't seem to find a solution that fits my needs.
I have a spreadsheet that has many individual sheets (sheet1,sheet2,sheet3...sheetx).
Sheet1 must always be visible.
Sheets 3,4,5....x must be hidden and protected such that they cannot be unhidden without unprotecting the workbook.
Sheet 2 must be normally hidden and protected as above but with the option of editing it after entering a password. The process of hiding and unhiding this sheet must not allow the user to see or unhide sheets 3,4,5....x
i.e the user must be able to hide,unhide and edit sheet 2 by use of a password but without ever allowing the user to see sheets 3,4,5,x etc.
Thanks again for having a look at this.
Charlie
You can try hiding sheet 2 (right click --> hide) and then password protecting the workbook.
But before that go to VBA and paste and run this:
Sub HideSheets
Worksheets("sheet3namehere").Visible =xlVeryHidden
Worksheets("sheet4namehere").Visible =xlVeryHidden
Worksheets("sheet5namehere").Visible =xlVeryHidden
End Sub
Doing this will remove the Unhide option for the above sheets from the user interface.
To unhide the sheets you will have to repeat the above but change xlVeryHidden to True.
Lastly you can password protect your vba project: Tools --> VBA Project Properties--> Protection. You can use a different password from the one that you have used for the workbook.
This way the needed sheets can be hidden without the Unhide option from the menu. While sheet2 can be still unhidden in the normal way if the user has the password to unprotect the workbook.

excel vba - only enable cell edits through code

I have an excel tool that gathers information from a user based on their login information. The information is stored in cells on one of the worksheets. If I wanted to lock these cells so they can't be updated manually, how can I go about doing that? If someone else logs in, obviously these cells would change. I hope to do it through VBA.
I only want to lock 6 cells... everything else should be editable...
Thanks
You can protect the worksheet with a password like this:
Private Sub Workbook_Open()
Sheets("sheetName").Protect Password:="YourPassword", UserInterfaceOnly:=True
End Sub
That will prevent users from manually making changes to the worksheet without entering the password. Your VBA code will still be able to make changes because you've set UserInterfaceOnly to True.
Note that users could easily view this password by navigating to the code through the Visual Basic editor. You can password protect the code as well, though: just right-click on the module, click on VBAProject Properties and go to the Protection tab.
See this page for more information: Excel VBA: Macro Code To Run Macros On Protected Worksheets & Sheets.
If these cells are the only ones on the sheet you want to protect, then just change the cell properties of the remaining cells by changing Locked property to false and leave the cells in question as Locked then protect the sheet using UserInterfaceOnly set to true (but realize that this doesn't work for all possible macro changes, so I usually avoid it.)
There are other methods that could work, but I think this is the best solution for you. If not, please add a comment to let me know.