LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.misc,microsoft.public.excel.programming,microsoft.public.scripting.vbscript
external usenet poster
 
Posts: 26
Default Creating Event procedures from a macro

Hi,

I'm using Jon Peltier's workaround (to Excel's inability to create
hyperlinks to chart sheets) to create a table of contents. The following
event procedure is placed in the code module for the "contents" sheet. It
activates the chart sheet when the user selects the linked cell:

' Thank you Jon!
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Range("B2")) Is Nothing Then
Charts("Chart1").Activate
End If
End Sub

This works fine, except that I need to create it on the fly from within a
macro. Here's what I've got so far:

ActiveWorkbook.VBProject.VBComponents("Contents"). CodeModule.InsertLines _

ActiveWorkbook.VBProject.VBComponents("Contents"). CodeModule.CreateEventProc
( _
"SelectionChange", "Worksheet") + 1, _
"MsgBox Hello"
Where "Contents" is the name of the worksheet where I want the event
procedure. The actual code I want to invoke inside the event procedure isn't
really "MsgBox Hello", but I can't even get this simple code to work. I get
"subscript out of range"....

For those of you who want to know more, the code I really want instead of
MsgBox is:

"If Not Intersect(Target, Range("B2")) Is Nothing Then
Charts("Chart1").Activate
End If"

I know this is a hard one. Can anyone provide any suggestions?

Thank you,

Robert Stober


 
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
Creating calendar that autopopulates dates based on event date ent TxKarateMama Excel Worksheet Functions 1 February 3rd 09 04:22 PM
Creating an annual marketing event calendar Scouser Tim Excel Discussion (Misc queries) 0 January 8th 08 02:49 PM
Event Macro running another macro inside K1KKKA Excel Discussion (Misc queries) 1 December 20th 06 08:21 PM
'Event' macro George Gee New Users to Excel 18 August 27th 05 12:50 PM
Event Macro stevepain Excel Discussion (Misc queries) 6 August 5th 05 05:11 AM


All times are GMT +1. The time now is 04:00 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"