Results 1 to 7 of 7

add a reference to Microsoft Visual Basic for Applications Extensibility" at run time

Threaded View

  1. #1
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    add a reference to Microsoft Visual Basic for Applications Extensibility" at run time

    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
    Last edited by jaslake; 08-18-2010 at 03:23 PM.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1