I have recorded a Macro with the desired alterations to the worksheet I want to, and would like to propagate these changes to 900 files. I have these files inside folders and sub-folders that might contain other Excel files as well. However, the files to be changed all have the same name (annual.xls). The macro code is:
When I run the macro above, it does not apply the changes to the other Excel files in the folder. What am I doing wrong?
Code:
Option Explicit
Sub fred()
'
' fred Macro
'
'
Dim fso As Object
Dim sFolder As String
Dim fFile As Object
Dim wb As Workbook
sFolder = "C:\Documents and Settings\fred\Desktop\Fred Liu\"
Set fso = CreateObject("Scripting.FileSystemObject")
Application.ScreenUpdating = False
For Each fFile In fso.getfolder(sFolder).Files
Set wb = Workbooks.Open(fFile.Path)
With wb
Columns("G:G").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Range("G1:CO477").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Locked = True
Selection.FormulaHidden = True
Columns("A:A").Select
Selection.Locked = True
Selection.FormulaHidden = False
Range("E1:E5").Select
Selection.Locked = True
Selection.FormulaHidden = False
Rows("6:8").Select
Selection.Locked = True
Selection.FormulaHidden = False
Range("F1:F5").Select
With Selection.Font
.Name = "Arial"
.FontStyle = "Regular"
.Size = 9
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.Color = 16711680
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With
Range("A24:F24").Select
Selection.Locked = False
Selection.FormulaHidden = False
Range("A35:F35").Select
Selection.Locked = False
Selection.FormulaHidden = False
ActiveWindow.SmallScroll Down:=15
Range("A49:F49").Select
Selection.Locked = False
Selection.FormulaHidden = False
ActiveWindow.SmallScroll Down:=15
Range("A58:F58").Select
Selection.Locked = False
Selection.FormulaHidden = False
Range("D55").Select
ActiveWindow.SmallScroll Down:=-579
Rows("27:27").Select
Selection.Locked = True
Rows("37:39").Select
Selection.Locked = True
ActiveWindow.ScrollRow = 9
ActiveWindow.ScrollRow = 10
ActiveWindow.ScrollRow = 11
ActiveWindow.ScrollRow = 12
ActiveWindow.ScrollRow = 13
ActiveWindow.ScrollRow = 14
ActiveWindow.ScrollRow = 15
ActiveWindow.ScrollRow = 16
ActiveWindow.ScrollRow = 17
ActiveWindow.ScrollRow = 18
ActiveWindow.ScrollRow = 19
ActiveWindow.ScrollRow = 20
ActiveWindow.ScrollRow = 21
ActiveWindow.ScrollRow = 22
ActiveWindow.ScrollRow = 23
ActiveWindow.ScrollRow = 24
ActiveWindow.ScrollRow = 25
ActiveWindow.ScrollRow = 26
ActiveWindow.ScrollRow = 27
ActiveWindow.ScrollRow = 28
ActiveWindow.ScrollRow = 29
ActiveWindow.ScrollRow = 30
ActiveWindow.ScrollRow = 31
ActiveWindow.ScrollRow = 32
ActiveWindow.ScrollRow = 33
ActiveWindow.ScrollRow = 34
Rows("51:51").Select
Selection.Locked = True
Rows("60:60").Select
Selection.Locked = True
Rows("66:66").Select
Selection.Locked = True
Range("E66").Select
ActiveWindow.ScrollRow = 35
ActiveWindow.ScrollRow = 36
ActiveWindow.ScrollRow = 38
ActiveWindow.ScrollRow = 39
ActiveWindow.ScrollRow = 40
ActiveWindow.ScrollRow = 41
ActiveWindow.ScrollRow = 42
ActiveWindow.ScrollRow = 43
ActiveWindow.ScrollRow = 44
ActiveWindow.ScrollRow = 45
ActiveWindow.ScrollRow = 46
ActiveWindow.ScrollRow = 47
ActiveWindow.ScrollRow = 48
ActiveWindow.ScrollRow = 49
ActiveWindow.ScrollRow = 50
ActiveWindow.ScrollRow = 51
ActiveWindow.ScrollRow = 52
ActiveWindow.ScrollRow = 53
ActiveWindow.ScrollRow = 54
ActiveWindow.ScrollRow = 55
ActiveWindow.ScrollRow = 56
ActiveWindow.ScrollRow = 57
ActiveWindow.ScrollRow = 58
ActiveWindow.ScrollRow = 59
ActiveWindow.ScrollRow = 60
ActiveWindow.ScrollRow = 61
ActiveWindow.ScrollRow = 62
ActiveWindow.ScrollRow = 63
ActiveWindow.ScrollRow = 64
ActiveWindow.ScrollRow = 65
ActiveWindow.ScrollRow = 66
Rows("69:75").Select
Selection.Locked = True
Rows("84:84").Select
Selection.Locked = True
Rows("92:93").Select
Selection.Locked = True
Rows("96:97").Select
Selection.Locked = True
Range("E97").Select
ActiveWindow.ScrollRow = 66
ActiveWindow.ScrollRow = 67
ActiveWindow.ScrollRow = 68
ActiveWindow.ScrollRow = 70
ActiveWindow.ScrollRow = 71
ActiveWindow.ScrollRow = 73
ActiveWindow.ScrollRow = 74
ActiveWindow.ScrollRow = 75
ActiveWindow.ScrollRow = 76
ActiveWindow.ScrollRow = 77
ActiveWindow.ScrollRow = 78
ActiveWindow.ScrollRow = 79
ActiveWindow.ScrollRow = 80
ActiveWindow.ScrollRow = 81
ActiveWindow.ScrollRow = 82
ActiveWindow.ScrollRow = 83
ActiveWindow.ScrollRow = 84
ActiveWindow.ScrollRow = 85
ActiveWindow.ScrollRow = 86
ActiveWindow.ScrollRow = 87
ActiveWindow.ScrollRow = 88
ActiveWindow.ScrollRow = 89
ActiveWindow.ScrollRow = 90
ActiveWindow.ScrollRow = 91
ActiveWindow.ScrollRow = 92
ActiveWindow.ScrollRow = 93
ActiveWindow.ScrollRow = 94
ActiveWindow.ScrollRow = 95
ActiveWindow.ScrollRow = 96
ActiveWindow.ScrollRow = 97
ActiveWindow.ScrollRow = 98
ActiveWindow.ScrollRow = 99
ActiveWindow.ScrollRow = 100
ActiveWindow.ScrollRow = 101
Rows("106:107").Select
Selection.Locked = True
Rows("111:111").Select
Selection.Locked = True
Rows("113:115").Select
Selection.Locked = True
Rows("122:123").Select
Selection.Locked = True
Range("D123").Select
ActiveWindow.ScrollRow = 102
ActiveWindow.ScrollRow = 103
ActiveWindow.ScrollRow = 104
ActiveWindow.ScrollRow = 105
ActiveWindow.ScrollRow = 106
ActiveWindow.ScrollRow = 107
ActiveWindow.ScrollRow = 108
ActiveWindow.ScrollRow = 109
ActiveWindow.ScrollRow = 110
ActiveWindow.ScrollRow = 111
ActiveWindow.ScrollRow = 112
ActiveWindow.ScrollRow = 113
ActiveWindow.ScrollRow = 114
ActiveWindow.ScrollRow = 115
ActiveWindow.ScrollRow = 116
ActiveWindow.ScrollRow = 117
ActiveWindow.ScrollRow = 118
ActiveWindow.ScrollRow = 119
Rows("125:125").Select
Selection.Locked = True
Rows("127:127").Select
Selection.Locked = True
Rows("129:129").Select
Selection.Locked = True
Rows("131:131").Select
Selection.Locked = True
Rows("132:193").Select
Selection.Locked = True
ActiveWindow.SmallScroll Down:=48
Rows("239:240").Select
Selection.Locked = True
Range("D247").Select
ActiveWorkbook.Save
ActiveWindow.SmallScroll Down:=-849
.Close True
End With
Next fFile
Application.ScreenUpdating = True
Set wb = Nothing
Set fso = Nothing
End Sub
When I run the macro above, it does not apply the changes to the other Excel files in the folder. What am I doing wrong?