Results 1 to 5 of 5

how to make macro file/workbook independant?

Threaded View

  1. #1
    Registered User
    Join Date
    08-09-2008
    Location
    San Jose
    Posts
    6

    how to make macro file/workbook independant?

    Hi All, I'm sure this is a simple one for your veterans....I'm just getting started with Excel macros. Below is a macro definition. I created this macro (Sort1) while inside a file named "FileA".

    I'm trying to make it so that this macro can be used inside any Excel file that I happen to be in. I have created/stored the excel macro in my Personal folder that is viewable to all other Excel files. The problem I'm having is that the macro below gets created with a hard-coded file name ("FileA"). How do I modify this macro so that it works on the "current file" (any Excel file that I happen to be in).

    Your help is greatly appreciated!
    Thanks,
    Chris



    Sub Sort1()
    '
    ' Sort1 Macro
    '
    
    '
        Rows("2:9").Select
        Range("AW2").Activate
        ActiveWorkbook.Worksheets("FileA").Sort.SortFields.Clear
        ActiveWorkbook.Worksheets("FileA").Sort.SortFields.Add Key:=Range( _
            "BH2:BH9"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
            xlSortNormal
        ActiveWorkbook.Worksheets("FileA").Sort.SortFields.Add Key:=Range( _
            "AW2:AW9"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
            xlSortNormal
        With ActiveWorkbook.Worksheets("FileA").Sort
            .SetRange Range("A2:BO9")
            .Header = xlGuess
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
    End Sub
    Last edited by Chris95120; 08-12-2008 at 02:28 AM. Reason: trying to follow posting rules...still learning...

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