Results 1 to 9 of 9

Thread: Vb6 And Excel Xp

  1. #1

    Thread Starter
    Hyperactive Member eranfox's Avatar
    Join Date
    May 2001
    Posts
    492

    Question Vb6 And Excel Xp

    Hello Everybody,
    i wrote the next code:
    '-------------------------------------------------------------------------
    Sub Main()
    Dim StrDay As String
    Dim StrMonth As String
    Dim StrYear As String
    Dim xlApp As Excel.Application
    Dim objWorkbook As Excel.Workbook
    Dim objWorksheet As Excel.Worksheet
    Dim EzorNo As String
    Dim ToPath As String
    Dim FromPath As String

    EzorNo = "07"

    Set xlApp = New Excel.Application
    xlApp.Visible = True
    xlApp.Workbooks.Open "\\myLib\myFolder\" & EzorNo & "\Base" & EzorNo & ".xlt"
    xlApp.Run ("Adding")
    xlApp.Quit
    Set objWorkbook = Nothing
    Set objWorksheet = Nothing
    Set xlApp = Nothing

    End Sub
    '-------------------------------------------------------------------------
    its working on Excel97 but it fails on ExcelXP

    i'm using VB6 SP5 and i have office2000 on my computer...

    thank you all in advance,
    ERAN
    Eran Fox
    ASSEMBLER,C,C++,VB6,SQL...

  2. #2
    Frenzied Member McGenius's Avatar
    Join Date
    Jan 2003
    Posts
    1,199
    When you're not sure which version of MS Office is installed on the destination machine I'd ercommend you to use late bindings instead of early:
    1. Delete all references to any of office product in your project
    2. Declare all Office related object variables As Object
    3. Use CreateObject function instead:
    Set xlApp = CreateObject("Excel.Application")
    4. Follow your original logic.
    McGenius

  3. #3
    PowerPoster
    Join Date
    Feb 2001
    Location
    Crossroads
    Posts
    3,046
    I didnt see anything in your code that would make it incompatible with EXCEL XP. I tested it on EXEL XP (except the Adding macro of course) and it worked fine. I did it with a reference to Excel10, though.

    Did you mean to say that it works on XP but not on 97? That would seem to make more sense to me. If so you can late bind by removing the reference and using CreateObject as was suggested. However, my personal preference would be to get a copy of Excel8.olb off the target box, copy to the development box, and reference that. That way you retain all the benefits of early binding ... intellisense especially.

    By the way ... what did the error say exactly when it crashed?

  4. #4
    Frenzied Member McGenius's Avatar
    Join Date
    Jan 2003
    Posts
    1,199
    Muddy,
    he said exactly what he did: he has Office 2K (version 9) and it's backward compatible with 97, but won't be with XP. That's why I suggested late bindings vs early: CreateObject will take care of all that versioning stuff.
    McGenius

  5. #5
    PowerPoster
    Join Date
    Feb 2001
    Location
    Crossroads
    Posts
    3,046
    Originally posted by McGenius
    Muddy,
    he said exactly what he did: he has Office 2K (version 9) and it's backward compatible with 97, but won't be with XP. That's why I suggested late bindings vs early: CreateObject will take care of all that versioning stuff.
    I have developed with a reference to Excel 9, and it has been compatible XP. Why shouldnt it be?

  6. #6

    Thread Starter
    Hyperactive Member eranfox's Avatar
    Join Date
    May 2001
    Posts
    492

    Reply to McGenius and Muddy

    Hello and thank you for your reply,
    So I understand that i need to take off the "Microsoft Excel 8.0 Object Library" from the references
    and insted of the following 3 lines:

    Dim xlApp As Excel.Application
    Dim objWorkbook As Excel.Workbook
    Dim objWorksheet As Excel.Worksheet

    to write :

    Dim xlApp As Object
    Dim objWorkbook As Object
    Dim objWorksheet As Object

    and to change:

    Set xlApp = New Excel.Application

    to:

    Set xlApp = CreateObject("Excel.Application")

    i'll try it

    Thank you both,
    Best regards,
    ERAN
    Eran Fox
    ASSEMBLER,C,C++,VB6,SQL...

  7. #7
    PowerPoster
    Join Date
    Feb 2001
    Location
    Crossroads
    Posts
    3,046
    I just ran it on XP with ref to Excel9 ... ran fine.

  8. #8
    PowerPoster
    Join Date
    Feb 2001
    Location
    Crossroads
    Posts
    3,046

    Re: Reply to McGenius and Muddy

    Originally posted by eranfox
    Hello and thank you for your reply,
    So I understand that i need to take off the "Microsoft Excel 8.0 Object Library" from the references
    and insted of the following 3 lines:

    Dim xlApp As Excel.Application
    Dim objWorkbook As Excel.Workbook
    Dim objWorksheet As Excel.Worksheet

    to write :

    Dim xlApp As Object
    Dim objWorkbook As Object
    Dim objWorksheet As Object

    and to change:

    Set xlApp = New Excel.Application

    to:

    Set xlApp = CreateObject("Excel.Application")

    i'll try it

    Thank you both,
    Best regards,
    ERAN
    Yes, that will late bind it. Minor point: You shouldnt need to Dim objWorkbook and objWorksheet as you arent using those variables anywhere.

  9. #9

    Thread Starter
    Hyperactive Member eranfox's Avatar
    Join Date
    May 2001
    Posts
    492

    Smile 2nd reply

    Hello again,
    I tried it and it worked super!!!
    Thanks a lot,
    ERAN
    Eran Fox
    ASSEMBLER,C,C++,VB6,SQL...

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