View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Application.Run for every open workbooks (one by one)

Notice your syntax:
"FirstFile.xls!SameMacroButStoredInThisSpecificWor kbook"

You have an exclamation mark after the workbook name and you use the workbook
name.

Application.Run "'" & wbk.name & "'!SameMacroButStoredInThisSpecificWorkbook"

The apostrophes are sometimes required--depending on the name of the file. But
they never hurt if you include them.

wrote:

Hi guys,

One question:

Do you know how to convert the macro:

Sub UglyMacro ()
Application.Run
"FirstFile.xls!SameMacroButStoredInThisSpecificWor kbook"
ActiveWindow.ActivateNext
Application.Run
"SecondFile.xls!SameMacroButStoredInThisSpecificWo rkbook"
ActiveWindow.ActivateNext
Application.Run
"ThirdFile.xls!SameMacroButStoredInThisSpecificWor kbook"
ActiveWindow.ActivateNext
End Sub

into macro that will go like:

Sub DraftNiceMacro ()
For each wbk in Application.Workbooks
Application.Run "wbk.SameMacroButStoredInThisSpecificWorkbook"
Next wbk
End Sub

This one is not working for some strange reason...

Thanks for your help,
Mark


--

Dave Peterson