Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How can I programmatically change Link references? | Links and Linking in Excel | |||
programmatically Set Reference to Library | Excel Programming | |||
Library references | Excel Programming | |||
Object Library References | Excel Programming | |||
Object Library References | Excel Programming |