Results 1 to 6 of 6

Thread: Automate Excel Question

  1. #1

    Thread Starter
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Exclamation

    I need to do a few things....
    I am creating a new workbook (no problem)
    I need to add Sheets after sheet3

    Dim O As Object
    Set O = CreateObject("excel.application")
    O.Visible = True
    O.Workbooks.Add
    O.sheets.Add

    Ok this is fine...but How do I make it add the sheet after Sheet3? (this way adds it before sheet1)

    Also...how Do I rename the sheets? (Or add sheet with new name)

    Thanks in Advance!

    (I will have more questions later...)
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  2. #2
    Junior Member
    Join Date
    Oct 2000
    Posts
    18
    Try something like this:

    Code:
    O.Sheets.Add
    
    'Change the name of the new sheet
    ActiveSheet.Name = "NewSheetName"
    
    'Move to the end
    ActiveSheet.Move After:=Sheets(Sheets.Count)

  3. #3
    Lively Member
    Join Date
    Oct 2000
    Location
    Chicago
    Posts
    97

    Here it is

    Hi,
    I can solve half of your problem ie, iam giving you the code for adding the sheet at the end but i don't know how to rename it..Sorry for that

    Here is the code for adding the sheet at the end

    ActiveWorkbook.Sheets.Add after:=Worksheets(Worksheets.Count)

    Happy Programming

    Regards

    Anil

  4. #4

    Thread Starter
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Talking Sweet!

    Great! That work (or close enough on the move one...I figured it out)
    Now...DO you know how to set the active sheet?
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  5. #5
    Junior Member
    Join Date
    Oct 2000
    Posts
    18
    When you select (activate) a sheet, the ActiveSheet objects references the currently activated sheet.

    Example:

    Code:
    Sheets("Sheet1").Select
    ActiveSheet.Name = "NewSheetName"
    
    'does the same as
    
    Sheets("Sheet1").Name = "NewSheetName"
    
    The ActiveSheet object is easier to use because you don't have to use the sheet name in every call.

  6. #6

    Thread Starter
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Talking Excellent....

    Thanks!!!
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

Posting Permissions

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



Click Here to Expand Forum to Full Width