Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 21st, 2004, 02:10 PM
Registered User
 
Join Date: Nov 2003
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default Include Library Reference at RunTime

The easy way to include a library reference is to Alt-F11 to VBA, then click Tools>References, and then pick one.

But I'd like sometimes to use a reference to the Office 11.0 Library and sometimes not.

Is there a way to add that reference programmatically when the xls opens ?

Thanks, Stoney
 
Old December 22nd, 2004, 06:53 AM
Authorized User
 
Join Date: Jun 2003
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I don't quite understand why you'd want to refernce/unreference the Office library from your VBA project, however the following are (untested) procedures to add and remove the references

Code:
Public Sub addRefToOffice()
  On Error Resume Next
  Application.VBE.ActiveVBProject.References.AddFromFile "C:\Program Files\Microsoft Office\Office11\MSO11.DLL"
End Sub

Public Sub removeRefToOffice()
  Dim ref As Object
  On Error Resume Next
  Set ref = Application.VBE.ActiveVBProject.References("Office")
  Application.VBE.ActiveVBProject.References.Remove ref
End Sub
Hope that gets you started
 
Old December 22nd, 2004, 12:48 PM
Registered User
 
Join Date: Nov 2003
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you !! That's exactly what I needed.
 
Old December 23rd, 2004, 12:37 PM
Registered User
 
Join Date: Nov 2003
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here's what happened and why I think I need to do this: this Excel project was developed and is on-going in Excel 2003 & Windows XP. It just surfaced that some users are in Excel 2000 and Windows 2000 - and will not upgrade soon.

So my thought, in an effort to avoid maintaining two developemnt projects, was to determine if the user was one of those 2000 guys, then add the 2000 references and remove the 2003 references.

How does that sound?
 
Old January 14th, 2005, 03:40 AM
Authorized User
 
Join Date: Jan 2005
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This is giving me great knowledge.

Thank you very much

Amjad






Similar Threads
Thread Thread Starter Forum Replies Last Post
How to include static library in c# nitesh kumar C# 2005 0 July 25th, 2008 12:45 AM
runtime automation error library not registered deco Pro VB 6 2 July 31st, 2007 08:09 AM
Code Library Reference ClaudiaCastle Access VBA 6 February 20th, 2007 12:23 PM
Add a reference on Runtime anandham Pro VB 6 3 September 18th, 2006 09:16 AM
Standard Library Reference resource markcholland BOOK: Professional C++ 0 March 17th, 2006 02:31 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.