Results 1 to 4 of 4

Thread: Created Excel Worksheet always becomes the 1st worksheet

Threaded View

  1. #1

    Thread Starter
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Created Excel Worksheet always becomes the 1st worksheet

    Why does that happen. I simply want any new worksheet to join the existing worksheets but after the existing worksheets.

    VB Code:
    1. Dim FileName As String
    2.         Dim UserPassword As String
    3.         UserPassword = "letmein"
    4.  
    5.         FileName = textbox1.text
    6.  
    7.         Dim objExcel As New Excel.Application
    8.         Dim oExcelWB As Excel.Workbook
    9.         Dim oExcelWS As Excel.Worksheet
    10.  
    11.         objExcel = CType(CreateObject("Excel.Application"), Excel.Application)
    12.         objExcel.Visible = False
    13.         oExcelWB = objExcel.Workbooks.Add()
    14.        
    15.         'RENAME EXISTING 3 WORKSHEETS
    16.         objExcel.Worksheets(1).name = "OPTION 1"
    17.         objExcel.Worksheets(2).name = "OPTION 2"
    18.         objExcel.Worksheets(3).name = "OPTION 3"
    19.  
    20.         'ADD NEW WORKSHEET
    21.         oExcelWS = objExcel.Worksheets.Add()
    22.         oExcelWS.Name = "OPTION 4"
    23.  
    24.    oExcelWB.Close(True, "D:\My Documents\" & FileName & ".xls")
    25.         oExcelWB = Nothing

    When I open the excel workbook the order is - Option 4 - Option 3 - etc...

    I need it to go 1 - 2 - 3 - 4
    Last edited by stimbo; Jul 27th, 2006 at 03:52 AM.

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