Wil Moosa
Well-known Member
- Joined
- Aug 11, 2002
- Messages
- 893
The code following extracts data from two different cells on sheet1(Annemie.Holland) into one cell on sheet2(1). It is meant to repair similar files in one folder.
The problem here is that it adresses sheet1 by the name "Annem.Hollander". This does not work when 20 files have a sheet1 with a different name here. Is there another way to adress sheet1?
Sub openfilesInALocation()
Dim i As Integer, wb As Workbook
With Application.FileSearch
.NewSearch
.LookIn = "C:\Users\Wil Moosa\Desktop\Updater\Vakantiekaart"
.SearchSubFolders = False
.Filename = "*.xls"
.Execute
For i = 1 To .FoundFiles.Count
'Open each workbook
Set wb = Workbooks.Open(Filename:=.FoundFiles(i))
'Repair month january
Sheets("1").Select
Sheets("1").Unprotect
Range("D11:F11").Select
ActiveSheet.Unprotect
Range("D11:F11").Select
ActiveCell.FormulaR1C1 = _
"='Annem. Hollander - '!R[7]C+'Annem. Hollander - '!R[9]C"
Range("D12:F12").Select
Sheets("1").Protect
'Save and close the workbook
wb.Save
wb.Close
'On to the next workbook
Next i
End With
End Sub
The problem here is that it adresses sheet1 by the name "Annem.Hollander". This does not work when 20 files have a sheet1 with a different name here. Is there another way to adress sheet1?
Sub openfilesInALocation()
Dim i As Integer, wb As Workbook
With Application.FileSearch
.NewSearch
.LookIn = "C:\Users\Wil Moosa\Desktop\Updater\Vakantiekaart"
.SearchSubFolders = False
.Filename = "*.xls"
.Execute
For i = 1 To .FoundFiles.Count
'Open each workbook
Set wb = Workbooks.Open(Filename:=.FoundFiles(i))
'Repair month january
Sheets("1").Select
Sheets("1").Unprotect
Range("D11:F11").Select
ActiveSheet.Unprotect
Range("D11:F11").Select
ActiveCell.FormulaR1C1 = _
"='Annem. Hollander - '!R[7]C+'Annem. Hollander - '!R[9]C"
Range("D12:F12").Select
Sheets("1").Protect
'Save and close the workbook
wb.Save
wb.Close
'On to the next workbook
Next i
End With
End Sub