Halley yenn
New Member
- Joined
- Mar 17, 2021
- Messages
- 32
- Office Version
- 365
- Platform
- Windows
Hi Folks,
Iam using the below code to open files in the folder and Lock from Column C to Column N and leave Column A and B unlocked, but I need to apply autofilter in the first row of each file and then lock
Column C2 to Column N& Last row.
Can someone help me here??
Option Explicit
Option Compare Text
Sub CellLocking()
Dim FSO As Object, MyFolder As Object
Dim fname As String, fpath As String, pwrd As String
Dim wb As Variant
Dim ws As Worksheet
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
pwrd = ("GRUG")
fpath = "enter you folderpath here" ' change as required
Set FSO = CreateObject("scripting.FileSystemObject")
Set MyFolder = FSO.GetFolder(fpath)
For Each wb In MyFolder.Files
If wb.name Like "*.xl*" Then
Set wb = Workbooks.Open(fpath & "\" & wb.name)
For Each ws In wb.Worksheets
ws.Range("A:B").Locked = False
ws.Range("C:N").Locked = True
ws.Protect (pwrd)
Next ws
End If
wb.Save
Next wb
Application.ScreenUpdating = True
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic
End Sub
KR,
H
Iam using the below code to open files in the folder and Lock from Column C to Column N and leave Column A and B unlocked, but I need to apply autofilter in the first row of each file and then lock
Column C2 to Column N& Last row.
Can someone help me here??
Option Explicit
Option Compare Text
Sub CellLocking()
Dim FSO As Object, MyFolder As Object
Dim fname As String, fpath As String, pwrd As String
Dim wb As Variant
Dim ws As Worksheet
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
pwrd = ("GRUG")
fpath = "enter you folderpath here" ' change as required
Set FSO = CreateObject("scripting.FileSystemObject")
Set MyFolder = FSO.GetFolder(fpath)
For Each wb In MyFolder.Files
If wb.name Like "*.xl*" Then
Set wb = Workbooks.Open(fpath & "\" & wb.name)
For Each ws In wb.Worksheets
ws.Range("A:B").Locked = False
ws.Range("C:N").Locked = True
ws.Protect (pwrd)
Next ws
End If
wb.Save
Next wb
Application.ScreenUpdating = True
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic
End Sub
KR,
H