Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can I set a reference in runtime?

Status
Not open for further replies.

Gwena

Programmer
Joined
Mar 11, 2004
Messages
42
Location
IL
Hello Hello,
Is there a way I can set a reference, say to outlook 9 or something like that, in run time and not in design time?
 
Gwena,
I don't think that is possible, but everytime I say that someone proves me wrong!
 
Erm...yes - that's exactly what late binding does...
 
Please explain...
 
Well, here's an example of late binding:

Dim x as Object
Set x = CreateObject("Word.Application")
 
Follow-up question.

This is my problem too. But my problem is regarding the version of an application, say Excel97 or Excel2000 or ExcelXP.

"Does this late binding affect the version that was installed in a workstation?"

We have lots of workstation here at work, and not all workstations are applicable for office upgrade. So some are still Excel97. But the workstation that i'm using for development has Excel2000. So, I'm having error when I run my application with workstation having only Excel97.

FYI. I set my references to Microsoft Excel 9.0 Object Library, and same with Word 9.0 and Outlook 10.0



Please pardon the grammar.
Not good in english.
 
Yes, late binding can be used to work around version issues.
 
Another follow-up for me to finish this.
c",)

Do I have to remove my references before compiling, If I use late binding?

Please pardon the grammar.
Not good in english.
 
And hey, I'm interested in this as well as I have exactly the same problem. Can you give examples of how to implement something to resolve this issue?
 
That's what strongm's post above does! You'll need to give a bit more detail of your code so far, and your problem to get more help.

Read faq222-2244 to see how to get better answers.


________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 
suoirotciv -

If you don't know 100% what version of Excel, Office, Word, etc that the users have installed, then using a reference will cause problems, so yes, go ahead and remove the reference. You would then use late binding via the CreateObject call.

If you look in your registry, you'll see that there's a version-independent key in there, and it can tell you what the latest version installed is. On my home machine, I have:
[ignore]
Excel.Sheet
|
+ CLSID
|
+ CurVer
|
+ Shell
[/ignore]
The value for CurVer is "Excel.Sheet.8". I can use this value in my call to CreateObject.

Sometimes you have to go via this indirect route. Different versions of Excel return different object types from this call. See:
Basically, Excel 97 returns a "Workbook" object and Excel 5.0, 7.0 return a "Worksheet" object. So you have handle things differently depending on the version of Excel they have installed (which the first registry call told you).

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
thanks for the info Chip H. (c",

i'll get back on this . . . need to test this thing first . . . but thank you for answering . . .

Please pardon the grammar.
Not good in english.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top