Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7956741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:04:58+00:00 2026-06-04T04:04:58+00:00

Reference I am trying to add code (a subroutine call) to a procedure within

  • 0

Reference

I am trying to add code (a subroutine call) to a procedure within Sheet1 by finding the line number of the procedure’s statement within sheet1 in VBE then adding the code to the next line over. The following code attempts to achieve this.

' This will search for and modify the appropriate Node#button_Click() subroutine
    With ActiveWorkbook.VBProject.VBComponents("Sheet1").CodeModule
            ProcLineNum = .ProcStartLine("Node" & NumNodes & "Button" & "_Click", 0)
            .InsertLines ProcLineNum + 1, "load_node_form(" & DQUOTE & "Node " & NumNodes & DQUOTE & ")"
    End With

The entire subroutine is the following:

Public Sub Node_Button_Duplication()
'
'Com: Copies and pastes Node 1's button to the appropriate column

Dim shp As Shape
Dim code As String
Dim ProcLineNum As Long
Const DQUOTE = """"

' Copy Node 1 button and paste in appropriate location

    ActiveSheet.Shapes("CommandButton1").Select
    Selection.Copy
    Cells(5, 10 + 7 * (NumNodes - 1) - 1).Select
    ActiveSheet.Paste
    Selection.ShapeRange.IncrementLeft 47.25
    Selection.ShapeRange.IncrementTop -13.5


    Set shp = ActiveSheet.Shapes(Selection.Name)

    With shp.OLEFormat.Object
        .Object.Caption = "Node" & Str(NumNodes)
        .Name = "Node" & NumNodes & "Button"
    End With

' This will search for and modify the appropriate Node#button_Click() subroutine
    With ActiveWorkbook.VBProject.VBComponents("Sheet1").CodeModule
            ProcLineNum = .ProcStartLine("Node" & NumNodes & "Button" & "_Click", 0)
            .InsertLines ProcLineNum + 1, "load_node_form(" & DQUOTE & "Node " & NumNodes & DQUOTE & ")"
    End With

End Sub

The subroutine will copy and paste a button (“CommandButton1”), rename it, then attempts to assign a subroutine call. The problem in finding the procedure is that once the new button is created, the “CommandButton#_Click() procedure doesn’t show up in VBE until I go and select it from the editor, thus causing an error when my code tries to search for that procedure.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T04:05:00+00:00Added an answer on June 4, 2026 at 4:05 am

    Is this what you are trying?

    Option Explicit
    
    Public Sub Node_Button_Duplication()
        Dim shp As Shape
        Dim code As String
        Dim ProcLineNum As Long, NumNodes As Long
    
        Const DQUOTE = """"
    
        ActiveSheet.Shapes("CommandButton1").Select
        Selection.Copy
        Cells(5, 10 + 7 * (NumNodes - 1) - 1).Select
        ActiveSheet.Paste
        Selection.ShapeRange.IncrementLeft 47.25
        Selection.ShapeRange.IncrementTop -13.5
    
        Set shp = ActiveSheet.Shapes(Selection.Name)
    
        With shp.OLEFormat.Object
            .Object.Caption = "Node" & Str(NumNodes)
            .Name = "Node" & NumNodes & "Button"
        End With
    
        With ActiveWorkbook.VBProject.VBComponents( _
        ActiveWorkbook.Worksheets("Sheet1").CodeName).CodeModule
            .InsertLines Line:=.CreateEventProc("Click", "Node" & NumNodes & "Button") + 1, _
            String:=vbCrLf & _
            "load_node_form(" & DQUOTE & "Node " & NumNodes & DQUOTE & ")"
        End With
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is the code from the class within which I am trying to reference
I get an exception on the List.Add line when trying to run this code:
I donwloaded Moq.4.0.10827 from www.code.google.com/p/moq and trying to add reference to Moq.4.0.10827\NET40\Moq.dll to Visual
As an example, I'm trying to add a reference to WatiN in Visual Studio
I wonder if someone can help me. I'm trying to add a reference to
I've been trying without success to add a reference to a public synonym in
In the below code, i am trying to reference an external .dll, which creates
I'm trying to add some functionality to our code base by using tied scalars.
I'm trying to add a script reference to jQuery in my master page so
I have a code like this where I am trying to add an event

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.