I have 100 excel files. They are in sub-folders. Each sub-folder has 10-15 excel files.
I would like to lock cells A1:A10 for all the 100 files in the sub-folders.
I've used VBA.
These are the different paths for example, C:\Users\mmishal001\Desktop\Project PT Attempt 3\DEMO2 for VBA\Director 1\Manager 1 C:\Users\mmishal001\Desktop\Project PT Attempt 3\DEMO2 for VBA\Director 1\Manager 2 C:\Users\mmishal001\Desktop\Project PT Attempt 3\DEMO2 for VBA\Director 2\Manager 3 C:\Users\mmishal001\Desktop\Project PT Attempt 3\DEMO2 for VBA\Director 2\Manager 4
Each of them has 10-15 files.
I've used the below code to write to the files - would be grateful if you could edit the below to lock cells A1:A10 for all the excel files in the above subfolders without having to write the functions again (maybe a loop?)
Sub TextInAll()
Dim my_files As String
Dim folder_path As String
Dim subfolder As String
Dim wb As Workbook
Dim ws As Worksheet
'Assign path to variable
folder_path = "C:\Users\mmishal001\Desktop\Project PT Attempt 3\DEMO2 for
VBA\Director 1\Manager 1"
'specifying file types or extn.
my_files = Dir(folder_path & "\*.xlsx")
Do While my_files <> vbNullString
Set wb = Workbooks.Open(folder_path & "\" & my_files)
Set ws = wb.Sheets(1)
ws.Range("A1:A5").Value = "mahir"
wb.Close True
my_files = Dir()
Loop
MsgBox ("All files are updated")
End Sub
I expect that one the code is run. When I go to any of the 100 files within the sub folders - the cell range A1:A10 is locked in each of the files.
javascript
andjava
tags? – Andreas