View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
[email protected] par_60056@hotmail.com is offline
external usenet poster
 
Posts: 42
Default VB code to set VBA References

On Jul 22, 10:44 pm, Sajit wrote:
I want to create a set of VB statements that will set the object references
required for my VBA code, such as, for the following,

Visual basic for applications
Microsoft Excel 11.0 Object Library
OLE Automation
Microsoft Office 11.0 Object Library
Microsoft Project 11.0 Object Library
Microsoft ActiveX Data Objects 2.8 Library
Microsoft ActiveX Data Objects Recordset 2.7 Library

Have them compiled to .exe and then call it at the start of my VBA code.

This is to create the references without the user having to do it themselves.

I suppose it would be necessary to check whether the refernces are already
set, if so then skip this step.

You could use the workbook_open event.

Private Sub Workbook_Open()
ActiveWorkbook.VBProject.References.AddFromGuid "{GUID of
References}", 1, 0

End Sub

You can find the right GUIDs by searching the registry if you don't
know them.

Peter Richardson