|
-
May 11th, 2003, 07:24 AM
#1
Thread Starter
Hyperactive Member
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...
-
May 11th, 2003, 08:00 AM
#2
Frenzied Member
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.
-
May 11th, 2003, 08:27 AM
#3
PowerPoster
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?
-
May 11th, 2003, 08:37 AM
#4
Frenzied Member
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.
-
May 11th, 2003, 08:52 AM
#5
PowerPoster
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?
-
May 11th, 2003, 08:54 AM
#6
Thread Starter
Hyperactive Member
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...
-
May 11th, 2003, 08:54 AM
#7
PowerPoster
I just ran it on XP with ref to Excel9 ... ran fine.
-
May 11th, 2003, 09:00 AM
#8
PowerPoster
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.
-
May 11th, 2003, 09:43 AM
#9
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|