Hi,
I require some assistance with a macro which loops through a number of files and calls the same macro in each of them. Unfortunately when I add "Application.Run..." to the code, it no longer loops through the process and instead stops after updating the first file in the loop. If I remove the "Application.Run..." code and add any other code, the loop works fine and it continues through the process repeating all the steps for each file found.
I was wondering if anyone might know why it stops after one file when using "Application.Run..." to call the macros?
NB I have a list of path and file names starting in row 8 of columns A and C. Each file in the list has a macro called UpdateS1 and promoupdate1.
Sub C_Run_Loop_Macro()
Dim lastRow As Long
Dim i As Long
Dim WB As Workbook
thiswkb = ActiveWorkbook.Name
Range("D5").ClearContents
Range("D8:D29").ClearContents
On Error Resume Next
For i = 8 To Range("B" & Rows.Count).End(xlUp).Row
Set WB = Workbooks.Open(Cells(i, "A").Value & "\" & Cells(i, "B").Value)
If Not WB Is Nothing Then
'-------------------------------------------------------------------------------
nwkb = ActiveWorkbook.Name
Application.Run ("'" & nwkb & "'!UpdateS1")
Application.Run ("'" & nwkb & "'!promoupdate1")
-------------------------------------------------------------------------------
Else
MsgBox "Please check path & folder for row " & i, vbExclamation
Exit Sub
End If
Next i
nwkb = Nothing
Set WB = Nothing
Cells(5, 4).Value = "Completed"
End Sub
Bookmarks