2 Problems: #1 Expand/Collapse groups in protected Worksheets & #2 Add username in worksheets.

Atiqul Haque

New Member
Joined
Dec 13, 2020
Messages
45
Office Version
  1. 2016
Platform
  1. Windows
Problem#1
Expand/Collapse groups in protected Worksheets:

When i put the following vba codes, it works only for one protected worksheet. But i need it for several protected worksheets.
Pls help someone to solve this issue. Your help will be highly appreciated.
Thanks in advance.


In a standard Module:
VBA Code:
Sub protect_sheet()
ActiveSheet.Unprotect "639"
Dim Sh As Worksheet
Set Sh = ThisWorkbook.Sheets("CBC_Report")
Sh.Protect "639", userinterfaceonly:=True
Sh.EnableOutlining = True
ActiveSheet.Protect "639"
End Sub

In ThisWorkbook:
VBA Code:
Private Sub Workbook_Open()
Dim Sh As Worksheet
Set Sh = ThisWorkbook.Sheets("CBC_Report")
Sh.Protect "639", userinterfaceonly:=True
Sh.EnableOutlining = True
End Sub


Problem#2
I need to Add Username in a fixed cell of a worksheet when a user login by Login Interface.
 
Last edited by a moderator:

Atiqul Haque

New Member
Joined
Dec 13, 2020
Messages
45
Office Version
  1. 2016
Platform
  1. Windows
Problem#1 has been solved. Complete code has given below for reference.


IN THISWORKBOOK
:

Private Sub Workbook_Open()

LoginInstance = o

Application.Visible = False

frmlogin.Show


Dim Sh As Worksheet
Set Sh = ThisWorkbook.Sheets("SheetName")
Sh.Protect "Password", userinterfaceonly:=True
Sh.EnableOutlining = True

End Sub

IN STANDARD MODULE:

Option Explicit

Sub protect_sheet()

Dim Sh As Worksheet
Set Sh = ThisWorkbook.Sheets("SheetName")

Sh.Protect "Password", userinterfaceonly:=True
Sh.EnableOutlining = True

End Sub
 

Some videos you may like

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.

Watch MrExcel Video

Forum statistics

Threads
1,127,696
Messages
5,626,361
Members
416,175
Latest member
LavendarRabbit

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top