Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default Is it possible to set a reference to a library in another file using VBA in Excel?

Hello, I am using VBA in Excel XP with Windows 2000

Is it possible to set a reference to a library in another file using VBA in Excel

For example, the main program resides in "File A" and it must programmatically set a reference to "Microsoft Outlook 10.0 Object Library" in "File B" for "File B's" use

If this is possible, can someone supply me with the code with which to do it

Thanks much in advance.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Is it possible to set a reference to a library in another file using VBA in Excel?

Hello, while I'm uncertain as to why this reference is a moving target, you can try the following

Sub Tester(
Dim n As Long, z As Boolea
With Workbooks("Book3").VBProject.Reference
For n = 1 To .Coun
If InStr(.Item(n).Description, "Microsoft Outlook") Then GoTo
Next
.AddFromGuid "{00062FFF-0000-0000-C000-000000000046}", 9,
z = Not
1: End Wit
Call HitIt(z
End Su

Private Sub HitIt(ByVal z As Boolean
Dim n As Lon
'Do your Stuf

'Remove reference if you set i
If z The
With Workbooks("Book3").VBProject.Reference
For n = 1 To .Coun
If InStr(.Item(n).Description, "Microsoft Outlook") The
.Remove .Item(n
Exit Fo
End I
Next
End Wit
End I
End Su

I currently don't have outlook on me, so this is untested, sorry

Regards
Nate Oliver
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default Is it possible to set a reference to a library in another file using VBA in Excel?

Thanks Nate. I'm curious, how/where did you get the GUID from? i.e. the line

..AddFromGuid "{00062FFF-0000-0000-C000-000000000046}", 9,

Thanks again...
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Is it possible to set a reference to a library in another file using VBA in Excel?

Hello Again

You can loop through your references as in my previous post, or have a peak at a specific reference, e.g.

Sub Grab_Reference(
Dim myRef As Objec
'3rd Referenc
Set myRef = ThisWorkbook.VBProject.References(3
If Not myRef Is Nothing The
Debug.Print myRef.Name & vbLf & myRef.Description &
vbLf & """" & myRef.GUID & """" & ", " &
myRef.Major & ", " & myRef.Minor & vbLf &
myRef.fullpat
End I
Set myRef = Nothin
End Su

Where you're in interested in the GUID and Major and Minor references. They can also be found in the registry

Also note, you can set the reference to the lowest Outlook library available using small major & minor versions, e.g.

..AddFromGuid "{00062FFF-0000-0000-C000-000000000046}", 1,

And, further note. Due to Excel XP's default settings, I'm pretty sure you'll need to trust Access to the VB project in your macro security settings. I would not bank on this setting being true for the majority of users. Late Binding may make sense if there's a reason as to why this reference might not be set

Regards
Nate Oliver
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Is it possible to set a reference to a library in another file using VBA in Excel?

A little better technique in terms of removing the reference might be to not loop

With ThisWorkbook.VBProject.Reference
.Remove !stdol
End Wit

Where stdole is the name of the library in question

Regards
Nate Oliver


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default Is it possible to set a reference to a library in another file using VBA in Excel?

Okay. Thanks for the assist and info. Its working perfectly.
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Is it possible to set a reference to a library in another file using VBA in Excel?

You are welcome. Hopefully you noted my non-looping
reference removal post.

Regards,
Nate Oliver


-----Original Message-----
Okay. Thanks for the assist and info. Its working

perfectly.

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
looking for an Excel macro function reference library for Excel 20 Max Excel Discussion (Misc queries) 3 December 28th 07 10:11 PM
Excel 2007 compatability, VBA Reference, MicrosoftOffice12. Object Library [email protected] Excel Discussion (Misc queries) 3 May 1st 07 06:57 PM
Excel add-in w/ Library.dll file, ? proper folder for the dll MoldMan Excel Discussion (Misc queries) 0 April 26th 06 10:27 PM
Excel library reference files Cindy Excel Programming 4 April 2nd 04 06:11 PM
Excel Object Library Reference francis cheuk Excel Programming 1 February 11th 04 06:15 PM


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

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

About Us

"It's about Microsoft Excel"