View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Claus Busch Claus Busch is offline
external usenet poster
 
Posts: 3,872
Default Opening a list of Excel files and run a macro in each

Hi Howard,

Am Fri, 14 Feb 2014 00:51:16 -0800 (PST) schrieb L. Howard:

The code opens this and two other workbooks with similar test names.


Option Explicit

Sub MyMacro()
MsgBox "Test book aaaaBooger"
Range("F1") = "aaaaBooger"
End Sub


I thought MyMacro is in ThisWorkbook the workbook from which you open
the other workbooks.
Try workbooks with different names. The macro fails if you have 3
workbooks with same names.

Try:

Sub Test()
Dim LRow As Long
Dim myRng As Range
Dim rngC As Range

Application.ScreenUpdating = False
LRow = Cells(Rows.Count, 1).End(xlUp).Row
Set myRng = ThisWorkbook.Sheets("Sheet1").Range("A1:A" & LRow)

For Each rngC In myRng
Workbooks.Open (rngC)
With ActiveWorkbook
Run ("'" & .Name & "'!MyMacro")
.Save
.Close
End With
Next
Application.ScreenUpdating = True
End Sub


Regards
Claus B.
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2