Results 1 to 3 of 3
  1. #1
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Wsheet name... (6.0)

    Why this loop not list in TEST the name of sheet in wbook and add in combobox?
    piece of code:
    ...............
    Dim XLS As Excel.Application
    Dim WBOOK As Excel.Workbook
    Dim WSHEET As Excel.Worksheet
    Dim RNG As Excel.Range
    Dim R As Integer
    Dim C As Integer
    Dim COUNTER As Integer
    Dim cntfileds As Integer
    Dim WSheetno As Integer
    Dim db As Database
    Dim rs As Recordset
    Dim TEST As String
    Private Sub Combo1_Click()
    On Error Resume Next:
    Call load_to_grid
    Save_to_database.Enabled = True
    End Sub
    Private Sub Load_excel_Click()
    On Error Resume Next

    With CommonDialog

    .DialogTitle = "Open Excel Files"

    .FileName = ""
    'Select a filter
    .Filter = "Excel Files (*.xls)" + Chr$(124) + "*.xls" + Chr$(124)
    .ShowOpen
    End With

    Textfile.Text = CommonDialog.FileName

    Set XLS = CreateObject("Excel.Application")

    Set WBOOK = XLS.Workbooks.Open(CommonDialog.FileName)

    For WSheetno = 1 To WBOOK.Worksheets.Count
    TEST = WSHEET.Name 'loads the no. of sheets in combo1
    Combo1.AddItem TEST
    Next


    WBOOK.Close False

    XLS.Quit

    End Sub
    ...............

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Wsheet name... (6.0)

    You don't set WSHEET anywhere, but because you have

    On Error Resume Next

    you don't see any error message. In general, you should avoid On Error Resume Next during testing.

    Add the following line immediately below For WSheetNo = ...

    Set WSHEET = WBOOK.Worksheets(WSheetno)

  3. #3
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Wsheet name... (6.0)

    sorry for delay...
    Work!
    tks.

Posting Permissions

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