Did you come across any requirement where you want the user to interact with a sheet only through VBA Form? A common way to achieve this is using Unprotect function available in VBA before making changes to the sheet and then protect it back using Protect function. See below an example:
Sheet1.Unprotect "123"
Sheet1.Range("A1").Value = "ABC"
Sheet1.Protect "123"
Sheet1.Protect Password:="123", UserInterfaceOnly:=True
In the code you will notice that UserInterfaceOnly has been passed as True that does the trick. If you protect a sheet with UserInterfaceOnly as True then Excel allows VBA to write data on the sheet without unprotecting it.
Sub ProtectSheet()
Sheet1.Protect Password:="123", UserInterfaceOnly:=True
End Sub
Thanks for reading the article, subscribe us to get more VBA tricks.
In MS Access, the best way to create a multiuser tool is to divide your solution. One part acts as interface and other one acts as database. You can have multiple copies of the interface distributed to users which are connected to central MS Access database saved at common shared drive. To connect the interface to database, you can use link table feature (Access>External Data>Import & Link) available in MS Access. Below is a commonly required VBA code which helps the developers to re-link MS Access linked tables when the database is renamed or moved to other location
Random Rows Selector is an MS Excel based tool which can be used to pick random or stratified samples from a set of records available in the Excel. The tool is fully dynamic, it can support any data format in Excel.
VBA Code To Delete All Shapes On A Excel sheet Here is a VBA code which deletes all the shapes from an Excel sheet. Code is simple but you have to be bit careful while…
How to send bulk emails from outlook using excel VBA? Have you ever felt the need of an Excel based VBA tool or code which can help you to draft Outlook emails in bulk by…
VBA Code To Add New Sheet In VBA, it is sometime important to add a worksheet at the right place in the Excel. Here is a simple an effective code that adds a new worksheet…
VBA Code to Filter Data in Excel Here is an easy reference code which filters data in the sheet. In the code, we have filtered the data in three steps. Step 1: Remove existing filter from…