Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
al al is offline
external usenet poster
 
Posts: 363
Default 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("Al l").CodeName).CodeModule

With VBCodeMod

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

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


End With

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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" wrote in message
...
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("Al l").CodeName).CodeModule

With VBCodeMod

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

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


End With

End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
al al is offline
external usenet poster
 
Posts: 363
Default 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" wrote in message
...
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("Al l").CodeName).CodeModule

With VBCodeMod

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

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


End With

End Sub




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
HOW TO CARRY A VAIABLE RESULTS FROM EXCEL SHEET PROCEDURE TO A MODULE CAPTGNVR Excel Discussion (Misc queries) 5 February 2nd 07 07:05 PM
to call procedure in a worksheet in a module CAPTGNVR Excel Discussion (Misc queries) 4 January 30th 07 09:39 PM
programmatically open VBE and go to a specified procedure in target module? DataFreakFromUtah Excel Programming 4 July 12th 04 05:37 PM
Lines in a Module(Procedure) Juan Melero Excel Programming 6 December 30th 03 12:38 AM


All times are GMT +1. The time now is 01:18 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"