Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 783
Default Adding library references programmatically

I have a procedure with code that requires that there be a reference to
Microsoft Scripting Runtime. Can that reference be accomplished
programmatically at the beginning of the procedure? If so, what is the
syntax?

Thanks,
Alan Beban
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Adding library references programmatically

Hi
you may use late binding. See:
http://www.xldynamic.com/source/xld.EarlyLate.html

--
Regards
Frank Kabel
Frankfurt, Germany


Alan Beban wrote:
I have a procedure with code that requires that there be a reference
to Microsoft Scripting Runtime. Can that reference be accomplished
programmatically at the beginning of the procedure? If so, what is
the syntax?

Thanks,
Alan Beban

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Adding library references programmatically

http://support.microsoft.com/default...b;en-us;160647
XL97: How to Programmatically Create a Reference

Add the scripting runtime manually, then you query it for particulars. You
might want to use the addfromGUID so you don't have to search for it.

This code Sub CCTester()
Dim refs As References
Dim rf As Reference
Set refs = ThisWorkbook.VBProject.References
For Each rf In refs
Debug.Print rf.Name, rf.GUID
Next
End Sub

showed
Scripting {420B2830-E718-11CF-893D-00A0C9054228}

and a variation showed:
Scripting C:\WINNT\system32\scrrun.dll

--
Regards,
Tom Ogilvy


"Alan Beban" wrote in message
...
I have a procedure with code that requires that there be a reference to
Microsoft Scripting Runtime. Can that reference be accomplished
programmatically at the beginning of the procedure? If so, what is the
syntax?

Thanks,
Alan Beban



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 205
Default Adding library references programmatically

Hi Alan,

Can that reference be accomplished
programmatically at the beginning of the procedure?


No, you't can set the reference at the start of the *procedure*. Excel
compiles workbooks module-by-module, so if you're dimming As
Dictionary, that would fail the compile before the code to add the
reference was run.

You could put the code to add the reference in a different module to
the code that uses the objects and make sure that's run first, but
doing that successfully means the VBProject will have to be unlocked
and the user will have to 'Trust access to visual basic project'.

Personally, I just ship my workbooks with the reference to the
scripting runtime set. I've yet to find a machine with Office installed
but not the scripting runtime.

Regards

Stephen Bullen
Microsoft MVP - Excel
www.oaltd.co.uk


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 783
Default Adding library references programmatically

Stephen Bullen wrote:
Hi Alan,


Can that reference be accomplished
programmatically at the beginning of the procedure?



No, you't can set the reference at the start of the *procedure*. Excel
compiles workbooks module-by-module, so if you're dimming As
Dictionary, that would fail the compile before the code to add the
reference was run.

You could put the code to add the reference in a different module to
the code that uses the objects and make sure that's run first, but
doing that successfully means the VBProject will have to be unlocked
and the user will have to 'Trust access to visual basic project'.

Personally, I just ship my workbooks with the reference to the
scripting runtime set. I've yet to find a machine with Office installed
but not the scripting runtime.

Regards

Stephen Bullen
Microsoft MVP - Excel
www.oaltd.co.uk


Thanks, Stephen, and to Tom Ogilvy and Frank Kabel as well, for
responding. I'll set the reference in the downloadable file at my web
site and hope that takes care of it. Since the error (if the reference
doesn't take) is a compile error, I don't see anything else to do
besides adding the comment at the beginning of the procedure indicating
that an effective library reference is required.

By the way, I take it that Frank's late binding comment is a red
herring; it certainly is for me, but that might be a statement about me
rather than about his comment :-)

Thanks again,
Alan Beban


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Adding library references programmatically


Hi Allen,

i have a proposal how you can dynamically add library references.
You open an empty EXCEL-file with an OLE-Connection, add a new modul
and import a small macro which looks like this:
Sub Set_Reference
Dim c As Object
Set c = Application.VBE.ActiveVBProject.References.AddFrom Guid(..)
End Sub

You save this EXCEL file, open the file again and start the macro wit
the appropriate method like (the coding depends on the language whic
which you build up the OLE-connection)

call method of H_WORKS 'SaveAs' Exporting #1 = filename
CALL METHOD OF H_WORKS 'Close'
CALL METHOD OF H_WORKS 'Open' = H_WORK EXPORTING
#1 = filename
CALL METHOD OF EXCEL1 'Run' EXPORTING #1 =
'Set_Reference'.

After this the new reference is set and you can add the macros whic
you want to execute the same way as described above. After this sav
the file, reopen it and start the macro you want.

I don't know if this is what you want, but i desperatly looking fo
this during the last weeks and was happy when i finally found it by m
own.

Take care
Guente

--
Guenter-Jose
-----------------------------------------------------------------------
Guenter-Josef's Profile: http://www.excelforum.com/member.php...fo&userid=2633
View this thread: http://www.excelforum.com/showthread.php?threadid=27370

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I programmatically change Link references? Boulder_dude Links and Linking in Excel 5 June 20th 08 09:44 PM
programmatically Set Reference to Library Todd uttenstine Excel Programming 6 April 30th 04 10:55 AM
Library references Amanda[_5_] Excel Programming 1 January 6th 04 06:40 PM
Object Library References Nelson[_5_] Excel Programming 5 December 10th 03 08:54 PM
Object Library References Nelson[_6_] Excel Programming 1 December 10th 03 03:31 AM


All times are GMT +1. The time now is 11:58 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"