+ Reply to Thread
Results 1 to 4 of 4

Applying macro to 'all opened files'

Hybrid View

  1. #1
    Registered User
    Join Date
    02-27-2009
    Location
    Newark, USA
    MS-Off Ver
    2007
    Posts
    29

    Applying macro to 'all opened files'

    Hi i have the following code:
    HTML Code: 
    I need that operation to be run on over 20 files. in the exact same cells and colunmns. I can insert the code in macro i already have for each file. But I rather just open all the files and then have this procedure applied to 'all opened files'. is that possible? and it is can i have the code?
    Thank you

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Applying macro to 'all opened files'

    Try

    Sub Test()
    For Each MyWorkbook In Workbooks
        MyWorkbook.Sheets(1).Range("B33").FormulaR1C1 = "=+R[-1]C*0.131"
        MyWorkbook.Sheets(1).Range("F33").FormulaR1C1 = "=+R[-1]C*0.141"
    Next MyWorkbook
    End Sub
    I've assumed that you always want to work on the first sheet in the workbook.
    Martin

  3. #3
    Registered User
    Join Date
    02-27-2009
    Location
    Newark, USA
    MS-Off Ver
    2007
    Posts
    29

    Re: Applying macro to 'all opened files'

    Martin, thank you.
    you bring up a good point:'the sheet'. The sheet is the same in all files. it is name after the month of the year. So now i am working in the june files and i have done this operation in the June sheet of each file. Next month it will be the July sheet. How do i change the above code to pick the correct sheet?
    Thanks again,

  4. #4
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Applying macro to 'all opened files'

    Sub Test()
    MyMonth = Application.InputBox("Type in month name", , , , , , , 2)
    For Each MyWorkbook In Workbooks
        MyWorkbook.Sheets(MyMonth).Range("B33").FormulaR1C1 = "=+R[-1]C*0.131"
        MyWorkbook.Sheets(MyMonth).Range("F33").FormulaR1C1 = "=+R[-1]C*0.141"
    Next MyWorkbook
    End Sub
    Try the above

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1