Hi
I've been on the WEB most of the day trying to figure this out. Is there code to "add a reference to Microsoft Visual Basic for Applications Extensibility" at run time.
I have this code that seems to require such a reference
' Modified from http://www.cpearson.com/excel/vbe.aspx
Public Sub DoModule8()
Dim VBProj As VBIDE.VBProject
Dim VBComp As VBIDE.VBComponent
Dim CodeMod As VBIDE.CodeModule
Dim LineNum As Long
Const DQUOTE = """" ' one " character
Set VBProj = ActiveWorkbook.VBProject
Set VBComp = VBProj.VBComponents("Sheet1")
Set CodeMod = VBComp.CodeModule
With CodeMod
LineNum = .CreateEventProc("Activate", "Worksheet")
LineNum = LineNum + 1
.InsertLines LineNum, "Selection.OnAction = " & DQUOTE & "DoModule5"
.InsertLines LineNum, "ActiveSheet.Shapes(" & DQUOTE & "Button " & 1 & DQUOTE & ").Select"
.InsertLines LineNum, "Selection.OnAction = " & DQUOTE & "DoModule1"
.InsertLines LineNum, "ActiveSheet.Shapes(" & DQUOTE & "Button " & 2 & DQUOTE & ").Select"
End With
End Sub
And it results in this (after I set the reference manually)
Option Explicit
Private Sub Worksheet_Activate()
ActiveSheet.Shapes("Button 2").Select
Selection.OnAction = "DoModule1"
ActiveSheet.Shapes("Button 1").Select
Selection.OnAction = "DoModule5"
End Sub
Can I set the Reference pragmatically?
As always, your help is deeply appreciated.
John
Bookmarks