Results 1 to 5 of 5

Thread: [RESOLVED] VB6 with MS Excel 2007...

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2007
    Posts
    200

    Resolved [RESOLVED] VB6 with MS Excel 2007...

    I used to work with VB6 and I referenced MSExcel 11.0 Library Object (MSoffice 2003). Now with MSOffice 2007, I am only given one choice of referenced MSExcel 12.0 Library Object

    here is the code:
    Code:
    ' in form
    Option Explicit
    
    Public xlApp As Excel.Application
    Public xlWB As Excel.Workbook
    Public xlWS As Excel.Worksheet
    
    ' in routine where I want to write to MS Excel 2007
    Private Sub StepCurrentCmd_Click()
    
    Dim DisplayStr As String
    Dim row As Integer
    Dim col As Integer
    
    Set xlApp = New Excel.Application
    Set xlWB = xlApp.Workbooks.Add
    Set xlWS = xlWB.Worksheets("sheet1")
    
    row = 2
    col = 1
    xlWS.Cells(row, col).value = DisplayStr      ' DisplayStr is an updated string
    col = col + 1
    
    End Sub
    The error is "Application-defined or Object-defined error"

    Essentially the error is at the line:
    xlWS.Cells(row, col).value = DisplayStr

    I noticed that the letter v in value (above) refuses to be capitalized. In the older application where I was using 11.0 library, the v in value automatically became capitalized. Is this the issue?

    thanks.
    Attached Files Attached Files

  2. #2
    Frenzied Member
    Join Date
    May 2006
    Location
    some place in the cloud
    Posts
    1,886

    Re: VB6 with MS Excel 2007...

    The only error I see, is
    Code:
    Set xlWS = xlWB.Worksheets("sheet1")
    Try with :
    Code:
    Set xlWS = xlWB.Worksheets(1)
    JG


    ... If your problem is fixed don't forget to mark your threads as resolved using the Thread Tools menu ...

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: VB6 with MS Excel 2007...

    Set xlWS = xlWB.Worksheets("sheet1")
    this should work. but there have been many posts about it not working in 2007, however i would expect a runtme error on that line if it is not working correctly

    test if xlWS is a valid worksheet object
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jun 2007
    Posts
    200

    Re: VB6 with MS Excel 2007...

    Hi. Still the same error:

    Run-time error '1004'
    Application-defined or Object-defined error

    I have tried:

    Code:
    Set xlWS = xlWB.Worksheets(1)
    The error seems to be with the excel defined-object. How do I check if it is correctly defined?

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jun 2007
    Posts
    200

    Re: VB6 with MS Excel 2007...

    I found the problem!

    Code:
    xlWS.Cells(row, col).value = DisplayStr
    col = col + 1
    If (col = 15) Then
      col = 1     REM  This line used to be col = 0.  Excel did not like this.
      row = row + 1
    End If
    Resolved! thanks for all your help.

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