Results 1 to 7 of 7

Thread: Excel

  1. #1

    Thread Starter
    Member
    Join Date
    May 2003
    Posts
    54

    Question Excel

    i have very simple question about EXCEL automation. I want to ADD worksheets in the Workbook and also want to give names to these worksheet.

    After Adding these worksheets also want to use (reference) these sheets one by one.

    VB Code:
    1. ActiveWorkbook.Sheets.Add , , 20
    2.     For iLoop = 1 to 20
    3.         'ActiveWorkbook.Sheets.Add After:=Worksheets(Worksheets.Count)
    4.         Set wSheet = ActiveWorkbook.ActiveSheet
    5.         wSheet.Name = sName & Format(iLoop, "00")
    6.     Next

    Problems that i am facing is that I could not get the reference of each sheet one by one ... so i can write data in that sheets.

    And MOST important after running my code, when i directly open the EXCEL (2000) it display me 20 sheets, even before running this code, it was displaying only three sheets as normally dose. And i do not want to change the default settings of the EXCEL.

    Thanx to all in advance.....

  2. #2

    Thread Starter
    Member
    Join Date
    May 2003
    Posts
    54
    Well i resolved one problem ... That is Number of Sheets as Default. Actually i write the following code which change the default setting of Excel.

    VB Code:
    1. AppExcel.SheetsInNewWorkbook = 40

    But i am still looking for
    1. Getting reference of Each WorkSheet, so i can write data on it.
    2. Change the name of WorkSheets

    Thanx to all in advance....

  3. #3

    Thread Starter
    Member
    Join Date
    May 2003
    Posts
    54

    Talking

    Well i am able to solve my problem . Thanx to all.

  4. #4

    Thread Starter
    Member
    Join Date
    May 2003
    Posts
    54

    Unhappy

    Now i am getting a new type of error

    Actually i am fromatting my Cells in the worksheet.... my code run fine for the first Worksheet but when same code run for the second or so on it give the error... Even in sheet data is written correctly....

    VB Code:
    1. Set wBook = AppExcel.Workbooks.Add
    2. ActiveWorkbook.Sheets.Add , , 30
    3.     Dim Count As Integer
    4.     For Count = 1 to 30
    5.  
    6.         Set wSheet = ActiveWorkbook.Sheets(Count)
    7.         wSheet.Name = Format(iDate, "dd-mm-yyyy")
    8.  
    9.         ' Column Headings
    10.         Dim iNumberOfFields As Single
    11.         iNumberOfFields = 6         'Fields to be Displayed
    12.        
    13.         Dim iHeadingStartRow, iHeadingStartCol As Single
    14.         iHeadingStartRow = 3
    15.         iHeadingStartCol = 2
    16.        
    17.         wSheet.Cells(iHeadingStartRow, iHeadingStartCol + 0).Value = "Colum 1"
    18.         wSheet.Cells(iHeadingStartRow, iHeadingStartCol + 1).Value = "Colum 12"
    19.         wSheet.Cells(iHeadingStartRow, iHeadingStartCol + 2).Value = "Colum 3"
    20.         wSheet.Cells(iHeadingStartRow, iHeadingStartCol + 3).Value = "Colum 4"
    21.         wSheet.Cells(iHeadingStartRow, iHeadingStartCol + 4).Value = "Colum 5"
    22.         wSheet.Cells(iHeadingStartRow, iHeadingStartCol + 5).Value = "Colum 6"
    23.            
    24.         ' Column Data
    25.         Dim iDataStartRow, iDataStartCol As Single
    26.         iDataStartRow = iHeadingStartRow + 1
    27.         iDataStartCol = iHeadingStartCol
    28.        
    29.         Dim iRow, iCol As Long
    30.         For iRow = iDataStartRow To 5 + iDataStartRow - 1    'Record Count + 3
    31.             For iCol = iDataStartCol To iNumberOfFields + iDataStartCol - 1 'Number of fields
    32.                 wSheet.Cells(iRow, iCol).Value = iRow + iCol
    33.             Next
    34.         Next
    35.        
    36.         'Format Colum Heading
    37.         Debug.Print iHeadingStartRow & vbTab & iHeadingStartCol & vbTab & iHeadingStartCol + iNumberOfFields
    38.  
    39. ' Error in the following line. BUT it WORK fine for the FIRST SHeet
    40.         Range(wSheet.Cells(iHeadingStartRow, iHeadingStartCol), wSheet.Cells(iHeadingStartRow, iHeadingStartCol + iNumberOfFields)).Select
    41. '.....
    42. Next

    Values printed in Debug window are
    3 2 8
    3 2 8

    which means that values are correct....

    Thanx to all in advance....

  5. #5

    Thread Starter
    Member
    Join Date
    May 2003
    Posts
    54
    Sorry i forget to write the error message

    message is "Select method of Range class failed"
    message number is " 1004 "

  6. #6

    Thread Starter
    Member
    Join Date
    May 2003
    Posts
    54
    Oaky... Thanx to all... i am able to resolve the problem. I missed very silly point.

    VB Code:
    1. wSheet.Name = Format(iDate, "dd-mm-yyyy")
    2. ' Following line is the key
    3. wSheet.Activate

  7. #7
    Lively Member
    Join Date
    Apr 2003
    Location
    Georgetown, Texas
    Posts
    114

    Me, Myself and I

    I guess that the above is what I would call "A Monologue"!

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