Hi all,
New to VBA and trying to figure out how to write a loop to run a macro on all files in a certain folder. I have found codes similar to the one below but am having trouble modifying it to fit my needs. The folder I'm trying to run it on is "C:\Users\\Documents\MS Analysis" and I'm trying to run a macro labeled MS_Survey_2
Any help would be greatly appreciated.
New to VBA and trying to figure out how to write a loop to run a macro on all files in a certain folder. I have found codes similar to the one below but am having trouble modifying it to fit my needs. The folder I'm trying to run it on is "C:\Users\\Documents\MS Analysis" and I'm trying to run a macro labeled MS_Survey_2
Any help would be greatly appreciated.
Code:
Sub nicework2()
Dim wbOpen As Workbook
Dim MyDir As String
MyDir = ActiveWorkbook.Path ' current path
Dim strExtension As String
'Comment out the 3 lines below to debug
'Application.ScreenUpdating = False
'Application.Calculation = xlCalculationManual
'On Error Resume Next
strExtension = Dir(MyDir & "\*.xlsx")
While strExtension <> vbNullString
Set wbOpen = Workbooks.Open(MyDir & "\" & strExtension)
With wbOpen
.Worksheets(1).Cells(1, 1).Value = "Hello"
.Close SaveChanges:=True
End With
strExtension = Dir
Wend
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub