+ Reply to Thread
Results 1 to 10 of 10

initiating a macro

  1. #1
    johnT
    Guest

    initiating a macro

    does anybody know why this doesn't work:

    Private Sub Workbook_NewSheet(ByVal Sh As Object)
    Set rng = Worksheets("Sheet1").Range("A1")
    i = 1

    For Each sht In Worksheets
    rng(i, 1) = sht.Name
    i = i + 1
    Next
    End Sub


  2. #2
    Andibevan
    Guest

    Re: initiating a macro

    John,

    It works fine for me,

    Is Sheet1 definately called "Sheet1"? (i.e. the tab on the excel workbook
    says "Sheet1".

    What do you mean by doesn't work - it did take ages to run for me but that
    may just be my laptop being funny.

    Regards

    Andi

    "johnT" <[email protected]> wrote in message
    news:[email protected]...
    > does anybody know why this doesn't work:
    >
    > Private Sub Workbook_NewSheet(ByVal Sh As Object)
    > Set rng = Worksheets("Sheet1").Range("A1")
    > i = 1
    >
    > For Each sht In Worksheets
    > rng(i, 1) = sht.Name
    > i = i + 1
    > Next
    > End Sub
    >




  3. #3
    Don Guillett
    Guest

    Re: initiating a macro

    If you are trying to put the tab name into cell a1 on each sheet, use this
    Sub shtname()
    For Each sht In Worksheets
    sht.Range("a1") = sht.Name
    Next
    End Sub

    --
    Don Guillett
    SalesAid Software
    [email protected]
    "johnT" <[email protected]> wrote in message
    news:[email protected]...
    > does anybody know why this doesn't work:
    >
    > Private Sub Workbook_NewSheet(ByVal Sh As Object)
    > Set rng = Worksheets("Sheet1").Range("A1")
    > i = 1
    >
    > For Each sht In Worksheets
    > rng(i, 1) = sht.Name
    > i = i + 1
    > Next
    > End Sub
    >




  4. #4
    Andibevan
    Guest

    Re: initiating a macro

    John,

    It works fine for me,

    Is Sheet1 definately called "Sheet1"? (i.e. the tab on the excel workbook
    says "Sheet1".

    What do you mean by doesn't work - it did take ages to run for me but that
    may just be my laptop being funny.

    Regards

    Andi

    "johnT" <[email protected]> wrote in message
    news:[email protected]...
    > does anybody know why this doesn't work:
    >
    > Private Sub Workbook_NewSheet(ByVal Sh As Object)
    > Set rng = Worksheets("Sheet1").Range("A1")
    > i = 1
    >
    > For Each sht In Worksheets
    > rng(i, 1) = sht.Name
    > i = i + 1
    > Next
    > End Sub
    >




  5. #5
    johnT
    Guest

    Re: initiating a macro

    I would like to list all worksheet tab names on one sheet
    such that when a new sheet is added, the list will
    automatically update
    >-----Original Message-----
    >If you are trying to put the tab name into cell a1 on

    each sheet, use this
    >Sub shtname()
    >For Each sht In Worksheets
    >sht.Range("a1") = sht.Name
    >Next
    >End Sub
    >
    >--
    >Don Guillett
    >SalesAid Software
    >[email protected]
    >"johnT" <[email protected]> wrote in

    message
    >news:[email protected]...
    >> does anybody know why this doesn't work:
    >>
    >> Private Sub Workbook_NewSheet(ByVal Sh As Object)
    >> Set rng = Worksheets("Sheet1").Range("A1")
    >> i = 1
    >>
    >> For Each sht In Worksheets
    >> rng(i, 1) = sht.Name
    >> i = i + 1
    >> Next
    >> End Sub
    >>

    >
    >
    >.
    >


  6. #6
    johnT
    Guest

    Re: initiating a macro

    Ok, the macro seems to work if I insert a new sheet, but
    is it possible to run the macro if I copy a sheet??

    >-----Original Message-----
    >John,
    >
    >It works fine for me,
    >
    >Is Sheet1 definately called "Sheet1"? (i.e. the tab on

    the excel workbook
    >says "Sheet1".
    >
    >What do you mean by doesn't work - it did take ages to

    run for me but that
    >may just be my laptop being funny.
    >
    >Regards
    >
    >Andi
    >
    >"johnT" <[email protected]> wrote in

    message
    >news:[email protected]...
    >> does anybody know why this doesn't work:
    >>
    >> Private Sub Workbook_NewSheet(ByVal Sh As Object)
    >> Set rng = Worksheets("Sheet1").Range("A1")
    >> i = 1
    >>
    >> For Each sht In Worksheets
    >> rng(i, 1) = sht.Name
    >> i = i + 1
    >> Next
    >> End Sub
    >>

    >
    >
    >.
    >


  7. #7
    Andibevan
    Guest

    Re: initiating a macro

    Not sure - one solution could be to do a count of the sheets when you open
    the workbook and have a macro which counts if the number of sheets increases
    then runs you code.

    "johnT" <[email protected]> wrote in message
    news:[email protected]...
    > Ok, the macro seems to work if I insert a new sheet, but
    > is it possible to run the macro if I copy a sheet??
    >
    > >-----Original Message-----
    > >John,
    > >
    > >It works fine for me,
    > >
    > >Is Sheet1 definately called "Sheet1"? (i.e. the tab on

    > the excel workbook
    > >says "Sheet1".
    > >
    > >What do you mean by doesn't work - it did take ages to

    > run for me but that
    > >may just be my laptop being funny.
    > >
    > >Regards
    > >
    > >Andi
    > >
    > >"johnT" <[email protected]> wrote in

    > message
    > >news:[email protected]...
    > >> does anybody know why this doesn't work:
    > >>
    > >> Private Sub Workbook_NewSheet(ByVal Sh As Object)
    > >> Set rng = Worksheets("Sheet1").Range("A1")
    > >> i = 1
    > >>
    > >> For Each sht In Worksheets
    > >> rng(i, 1) = sht.Name
    > >> i = i + 1
    > >> Next
    > >> End Sub
    > >>

    > >
    > >
    > >.
    > >




  8. #8
    johnT
    Guest

    Re: initiating a macro

    do you have some sample code that i can copy??
    >-----Original Message-----
    >Not sure - one solution could be to do a count of the

    sheets when you open
    >the workbook and have a macro which counts if the number

    of sheets increases
    >then runs you code.
    >
    >"johnT" <[email protected]> wrote in

    message
    >news:[email protected]...
    >> Ok, the macro seems to work if I insert a new sheet, but
    >> is it possible to run the macro if I copy a sheet??
    >>
    >> >-----Original Message-----
    >> >John,
    >> >
    >> >It works fine for me,
    >> >
    >> >Is Sheet1 definately called "Sheet1"? (i.e. the tab on

    >> the excel workbook
    >> >says "Sheet1".
    >> >
    >> >What do you mean by doesn't work - it did take ages to

    >> run for me but that
    >> >may just be my laptop being funny.
    >> >
    >> >Regards
    >> >
    >> >Andi
    >> >
    >> >"johnT" <[email protected]> wrote in

    >> message
    >> >news:[email protected]...
    >> >> does anybody know why this doesn't work:
    >> >>
    >> >> Private Sub Workbook_NewSheet(ByVal Sh As Object)
    >> >> Set rng = Worksheets("Sheet1").Range("A1")
    >> >> i = 1
    >> >>
    >> >> For Each sht In Worksheets
    >> >> rng(i, 1) = sht.Name
    >> >> i = i + 1
    >> >> Next
    >> >> End Sub
    >> >>
    >> >
    >> >
    >> >.
    >> >

    >
    >
    >.
    >


  9. #9
    Don Guillett
    Guest

    Re: initiating a macro

    I misunderstood your original question but put this in the ThisWorkbook
    module to run each time you open the workbook or you could run manually from
    a button. No need to recount.

    Private Sub Workbook_Open()
    For i = 1 To Worksheets.Count
    Sheets("sheet1").Cells(i, 1) = Sheets(i).Name
    Next i
    End Sub

    --
    Don Guillett
    SalesAid Software
    [email protected]
    "johnT" <[email protected]> wrote in message
    news:[email protected]...
    > do you have some sample code that i can copy??
    > >-----Original Message-----
    > >Not sure - one solution could be to do a count of the

    > sheets when you open
    > >the workbook and have a macro which counts if the number

    > of sheets increases
    > >then runs you code.
    > >
    > >"johnT" <[email protected]> wrote in

    > message
    > >news:[email protected]...
    > >> Ok, the macro seems to work if I insert a new sheet, but
    > >> is it possible to run the macro if I copy a sheet??
    > >>
    > >> >-----Original Message-----
    > >> >John,
    > >> >
    > >> >It works fine for me,
    > >> >
    > >> >Is Sheet1 definately called "Sheet1"? (i.e. the tab on
    > >> the excel workbook
    > >> >says "Sheet1".
    > >> >
    > >> >What do you mean by doesn't work - it did take ages to
    > >> run for me but that
    > >> >may just be my laptop being funny.
    > >> >
    > >> >Regards
    > >> >
    > >> >Andi
    > >> >
    > >> >"johnT" <[email protected]> wrote in
    > >> message
    > >> >news:[email protected]...
    > >> >> does anybody know why this doesn't work:
    > >> >>
    > >> >> Private Sub Workbook_NewSheet(ByVal Sh As Object)
    > >> >> Set rng = Worksheets("Sheet1").Range("A1")
    > >> >> i = 1
    > >> >>
    > >> >> For Each sht In Worksheets
    > >> >> rng(i, 1) = sht.Name
    > >> >> i = i + 1
    > >> >> Next
    > >> >> End Sub
    > >> >>
    > >> >
    > >> >
    > >> >.
    > >> >

    > >
    > >
    > >.
    > >




  10. #10
    johnT
    Guest

    Re: initiating a macro

    Gentlemen,

    I came up with something that works for me, based on all
    your feedback, thanks for all your help.

    >-----Original Message-----
    >I misunderstood your original question but put this in

    the ThisWorkbook
    >module to run each time you open the workbook or you

    could run manually from
    >a button. No need to recount.
    >
    >Private Sub Workbook_Open()
    >For i = 1 To Worksheets.Count
    >Sheets("sheet1").Cells(i, 1) = Sheets(i).Name
    >Next i
    >End Sub
    >
    >--
    >Don Guillett
    >SalesAid Software
    >[email protected]
    >"johnT" <[email protected]> wrote in

    message
    >news:[email protected]...
    >> do you have some sample code that i can copy??
    >> >-----Original Message-----
    >> >Not sure - one solution could be to do a count of the

    >> sheets when you open
    >> >the workbook and have a macro which counts if the

    number
    >> of sheets increases
    >> >then runs you code.
    >> >
    >> >"johnT" <[email protected]> wrote in

    >> message
    >> >news:[email protected]...
    >> >> Ok, the macro seems to work if I insert a new sheet,

    but
    >> >> is it possible to run the macro if I copy a sheet??
    >> >>
    >> >> >-----Original Message-----
    >> >> >John,
    >> >> >
    >> >> >It works fine for me,
    >> >> >
    >> >> >Is Sheet1 definately called "Sheet1"? (i.e. the tab

    on
    >> >> the excel workbook
    >> >> >says "Sheet1".
    >> >> >
    >> >> >What do you mean by doesn't work - it did take ages

    to
    >> >> run for me but that
    >> >> >may just be my laptop being funny.
    >> >> >
    >> >> >Regards
    >> >> >
    >> >> >Andi
    >> >> >
    >> >> >"johnT" <[email protected]> wrote

    in
    >> >> message
    >> >> >news:[email protected]...
    >> >> >> does anybody know why this doesn't work:
    >> >> >>
    >> >> >> Private Sub Workbook_NewSheet(ByVal Sh As Object)
    >> >> >> Set rng = Worksheets("Sheet1").Range("A1")
    >> >> >> i = 1
    >> >> >>
    >> >> >> For Each sht In Worksheets
    >> >> >> rng(i, 1) = sht.Name
    >> >> >> i = i + 1
    >> >> >> Next
    >> >> >> End Sub
    >> >> >>
    >> >> >
    >> >> >
    >> >> >.
    >> >> >
    >> >
    >> >
    >> >.
    >> >

    >
    >
    >.
    >


+ 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