AutoRun Macro on Opening of File

  • I have a macro I run to sort data.


    Can someone help me complete the code to have this run everytime I open the file that this macro is in?


    [vba]
    Sub sortB()
    '
    ' sort Macro
    ' Macro recorded 29/12/2005 by Tayler Reid
    '
    '
    Range("B7:BG106").Select
    Selection.sort Key1:=Range("B7"), Order1:=xlAscending, Header:=xlGuess, _
    OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
    DataOption1:=xlSortNormal
    Range("B7").Select
    End Sub
    [/vba]

    Tayler [the blue fox] :thanx:

  • Re: AutoRun Macro on Opening of File


    Hi there:


    You have to put your code under the workbook open event. To do this. Open your VBA Project Window and double clike on Thisworkbook and on top of the right Pane select Workbook and Select the event as Open.
    In your code change this

    Code
    Range("B7:BG106").Select


    to


    Code
    Sheets("SheetName").Range("B7:BG106").select


    Regards


    Maqbool

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!