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 February 10th, 2005, 02:17 PM
Authorized User
 
Join Date: Jun 2003
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default Addin Project References

Hi --

    How can I check programmatically that a workbook has a project reference to an AddIn and if it doesn't, then add it.

    I know how to do it manually using the Tools\Reference menu option in the VBA editor, but I don't know how to let the workbook do it.

Thanks,

Barry




 
Old February 10th, 2005, 08:11 PM
Authorized User
 
Join Date: Jun 2003
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
Default

you want to do something like (untested):

Code:
Public Sub buildRefs()
  Call assertRef("C:\Program Files\Microsoft Office\Office11\XLStart\Book1.xla")
  Call assertRef("C:\windows\system32\msxml2.dll")
End Sub

Private Sub assertRef(fileSpec As String)
  If Not addRef(fileSpec) Then
    debug.print "Reference to " & fileSpec & " was unsuccessful"
  End If
End Sub

Private Function addRef(fileSpec As String) As boolean
  On Error Resume Next
  If Not doesRefExist(fileSpec) Then
    activeWorkbook.VBProject.References.AddFromFile fileSpec
  End If
  addRef = (Err.Number = 0)
End Function

private Function doesRefExist(fileSpec As string) As Boolean
  Dim ref As Object
  For Each ref In ThisWorkbook.VBProject.References
    If StrComp(ref.FullPath, fileSpec, vbTextCompare) = 0 Then
      doesRefExist = True
      Exit For
    End If
  Next
End Function
ie. running the "buildRefs" procedure adds references to an XLA addin, and a DLL. Is this what you mean?





Similar Threads
Thread Thread Starter Forum Replies Last Post
References and VB ’05 Web Project BrianWren Visual Basic 2005 Basics 0 December 15th, 2006 04:23 PM
Legacy references in a duplicate project JohnS VS.NET 2002/2003 0 March 10th, 2005 02:08 PM
Addin narendrapawar VB How-To 0 January 5th, 2005 09:30 AM
Adding Web References to a project.... vb_developer C# 0 September 5th, 2004 01:32 AM
closing a project is a problem inside an addin... gbianchi Pro VB 6 2 September 1st, 2003 01:46 PM





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