+ Reply to Thread
Results 1 to 3 of 3

Add Procedure To Module Via VBA

  1. #1
    Al
    Guest

    Add Procedure To Module Via VBA

    I'd like to add a Procedure to a Worksheet Module via VBA.
    The problem is that the module already contains a procedure,
    so I need to learn how to add the procedure UNDER the existing procedure.
    Attached is the procedure I'd like to add. Thanks in advance.


    Sub addselectionchange()
    Dim StartLine As Long
    Dim VBCodeMod As CodeModule
    Dim DEPT3 As String
    Dim LINENUM As Integer

    Set VBCodeMod =
    ThisWorkbook.VBProject.VBComponents(Worksheets("All").CodeName).CodeModule

    With VBCodeMod

    StartLine = .CreateEventProc("SelectionChange", "Worksheet") + 1

    .InsertLines StartLine, _
    "lastAddress = Target.Address"


    End With

    End Sub

  2. #2
    Bob Phillips
    Guest

    Re: Add Procedure To Module Via VBA

    Al,

    Have you tried this. It does exactly what you want?

    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "Al" <[email protected]> wrote in message
    news:[email protected]...
    > I'd like to add a Procedure to a Worksheet Module via VBA.
    > The problem is that the module already contains a procedure,
    > so I need to learn how to add the procedure UNDER the existing procedure.
    > Attached is the procedure I'd like to add. Thanks in advance.
    >
    >
    > Sub addselectionchange()
    > Dim StartLine As Long
    > Dim VBCodeMod As CodeModule
    > Dim DEPT3 As String
    > Dim LINENUM As Integer
    >
    > Set VBCodeMod =
    > ThisWorkbook.VBProject.VBComponents(Worksheets("All").CodeName).CodeModule
    >
    > With VBCodeMod
    >
    > StartLine = .CreateEventProc("SelectionChange", "Worksheet") + 1
    >
    > .InsertLines StartLine, _
    > "lastAddress = Target.Address"
    >
    >
    > End With
    >
    > End Sub




  3. #3
    Al
    Guest

    Re: Add Procedure To Module Via VBA

    Bob:

    Thanks for responding.

    The procedure itself runs fine if there ISNT another procedure in the module
    I want to copy this procedure to.

    The problem is that there is already another procedure within the module
    that I need this procedure in. It attempts to overwrite that procedure.
    Consequently Errors are caused and Excel eventually shuts down Completely.

    "Bob Phillips" wrote:

    > Al,
    >
    > Have you tried this. It does exactly what you want?
    >
    > --
    >
    > HTH
    >
    > RP
    > (remove nothere from the email address if mailing direct)
    >
    >
    > "Al" <[email protected]> wrote in message
    > news:[email protected]...
    > > I'd like to add a Procedure to a Worksheet Module via VBA.
    > > The problem is that the module already contains a procedure,
    > > so I need to learn how to add the procedure UNDER the existing procedure.
    > > Attached is the procedure I'd like to add. Thanks in advance.
    > >
    > >
    > > Sub addselectionchange()
    > > Dim StartLine As Long
    > > Dim VBCodeMod As CodeModule
    > > Dim DEPT3 As String
    > > Dim LINENUM As Integer
    > >
    > > Set VBCodeMod =
    > > ThisWorkbook.VBProject.VBComponents(Worksheets("All").CodeName).CodeModule
    > >
    > > With VBCodeMod
    > >
    > > StartLine = .CreateEventProc("SelectionChange", "Worksheet") + 1
    > >
    > > .InsertLines StartLine, _
    > > "lastAddress = Target.Address"
    > >
    > >
    > > End With
    > >
    > > End Sub

    >
    >
    >


+ Reply to Thread

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