View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
RB Smissaert RB Smissaert is offline
external usenet poster
 
Posts: 2,452
Default Programatically Enable VBIDE Reference?

Here some general purpose code:

Sub AddReference(strGUID As String, _
Optional lMajor As Long, _
Optional lMinor As Long, _
Optional strWorkbook As String)

Dim oRef As Object
Dim oVBProj As Object

On Error Resume Next

If Len(strWorkbook) = 0 Then
strWorkbook = ThisWorkbook.Name
End If

Set oVBProj = Workbooks(strWorkbook).VBProject

Set oRef = oVBProj.References.AddFromGuid(GUID:=strGUID, _
Major:=lMajor, _
Minor:=lMinor)

End Sub


Sub test()

AddReference "{0002E157-0000-0000-C000-000000000046}"

End Sub


RBS


"RayportingMonkey" wrote in
message ...
First off, let me say that I never use my "power" for evil... Only for
good!

Now, with that out of the way...

I have a script that creates a series of new workbooks and copies certain
data into them. I need to track who is using these reports, but they are
distributed on a SharePoint where statistics have not been enabled.

So, I have written a simple OnOpen script that appends a log with date,
time, ThisWorkook.Name and Application.UserName. Grant it, if the user
does
not enable macros I don't get the data anyway, but this is a pilot and we
just need a good idea of who is using them.

Anyway, I have another routine that copies the necessary code into the
ThisWorkbook object, but in order for it to execute, I need to enable a
reference to "Microsoft Visual Basic For Applications Extensibility 5.3"
on
the new workbook.

I can make everything else run automatically, but for each new workbook,
it
seems I would have to manually set this reference, which defeats my
purpose...

Is there a way to programatically enable a reference to "Microsoft Visual
Basic For Applications Extensibility 5.3"?

Is there a different/better method of setting up both a private sub and an
OnOpen event in a new workbook?

Any enlightenment would help me in this dark place!

Regards,
Ray

--
"Trying to make reports so easy... even a monkey could run ''em!"