LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Programmatically Adding a Worksheet_Change Event Procedure to a Pr

I am using Excel 2003 and have added a script to add a Worksheet_Change Event
to an Added Worksheet. I receive the following error: Error -2147417848
(80010108): The object invoked has disconnected from its clients.



I have referenced the Microsoft Visual Basic for Applications Extensibility
5.3. I understand this script would run in the background and naming
VBProject as an Object and using the CreateObject as Microsoft describes in
Article ID: 319832 - Last Review: February 1, 2007 - Revision: 5.3

INFO: Error or Unexpected Behavior with Office Automation When You Use Early
Binding in Visual Basic
does not work.



Here is a portion of the script and where the ERROR occurs:



Dim wsn As String

Dim VBProj As VBIDE.VBProject

Dim VBComp As VBIDE.VBComponent

Dim CodeMod As VBIDE.CodeModule

Dim LineNum As Long

Const DQUOTE = """"



wsn = ActiveSheet.Name



Application.EnableEvents = False

Set VBProj = ActiveWorkbook.VBProject

Set VBComp = VBProj.VBComponents(Worksheets(wsn).CodeName).Code Module

Set CodeMod = VBComp.Document



With CodeMod

LineNum = .CountOfLines + 1

.InsertLines LineNum, "Option Explicit" & vbCrLf

LineNum = LineNum + 1

.InsertLines LineNum, vbCrLf

LineNum = LineNum + 1

.InsertLines LineNum, _

"Private Sub Worksheet_Change(ByVal Target As Range)" & vbCrLf

LineNum = LineNum + 1 (Here is where I receive the ERROR)

.InsertLines LineNum, "Dim rngDV As Range" & vbCrLf

LineNum = LineNum + 1

.InsertLines LineNum, "Dim oldVal As String" & vbCrLf




 
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
Programmatically adding checkbox and attaching event handlers guest Excel Programming 3 June 10th 08 07:24 PM
adding usr defined event procedure of textbox in usrform ?? tom taol Excel Programming 2 December 30th 04 12:13 PM
Worksheet_Change procedure [email protected] Excel Programming 1 September 3rd 04 01:53 AM
Worksheet_Change procedure [email protected] Excel Programming 1 September 3rd 04 01:48 AM
Worksheet_Change procedure [email protected] Excel Programming 1 September 3rd 04 01:23 AM


All times are GMT +1. The time now is 06:34 AM.

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

About Us

"It's about Microsoft Excel"