+ Reply to Thread
Results 1 to 2 of 2

How to make a macro to be able to run in other workbook?

  1. #1
    Registered User
    Join Date
    02-20-2012
    Location
    New York, US
    MS-Off Ver
    Excel 2007
    Posts
    1

    How to make a macro to be able to run in other workbook?

    Hi all I have a very quick question here. I have this code as attached to auto filter the data by the criteria in the code. However it can only run the filtering when the data is in the same workbook as this code.
    There must be somewhere in the code that I can change to make it applicable to other workbook right? Please enlighten me, thank you very much!
    Attached Files Attached Files

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: How to make a macro to be able to run in other workbook?

    Hi,

    In the same way as you have set up a sheet variable (albeit always the ActiveSheet), you need to create a workbook Variable, e.g
    wbMyBook as Workbook.

    Then fully reference the range to be filtered. Something like.

    wbMyBook.Sheets(oWS.Name).UsedRange.AutoFilter Field:=4, Criteria1:=arCriteria(index), Operator:=xlFilterValues

    Note you'll also need to include the array index in the arCriteria variable
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

+ 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