Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
bac bac is offline
external usenet poster
 
Posts: 76
Default Remove VBA code behind a worksheet

I have a worksheet with an event handler:

Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo xitsub

If Target.Address = "$W$7" Then
After_AIF

Else

End If
xitsub:
End Sub

The After_AIF function is in "Module1" which I delete when the workbook is
saved:

'Delete VB Code
Dim x As Object

Set x = Application.VBE.ActiveVBProject.VBComponents
x.Remove VBComponent:=x.Item("Module1")

My question is how do I delete the "Private Sub Worksheet_Change(ByVal
Target As Range)" sub? I'm getting what is apparently a compile error before
the "new" workbook closes.

I've tried:

x.Remove VBComponent:=x.Item("worksheet").code and several variants of the
VBComponenet:= thingy without success..

TIA

ABC


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,718
Default Remove VBA code behind a worksheet

With ThisWorkbook.VBProject.VBComponents("Sheet1")
.CodeModule.DeleteLines 1, .CodeModule.CountOfLines
End With


--
Jim
"BAC" wrote in message
...
|I have a worksheet with an event handler:
|
| Private Sub Worksheet_Change(ByVal Target As Range)
| On Error GoTo xitsub
|
| If Target.Address = "$W$7" Then
| After_AIF
|
| Else
|
| End If
| xitsub:
| End Sub
|
| The After_AIF function is in "Module1" which I delete when the workbook is
| saved:
|
| 'Delete VB Code
| Dim x As Object
|
| Set x = Application.VBE.ActiveVBProject.VBComponents
| x.Remove VBComponent:=x.Item("Module1")
|
| My question is how do I delete the "Private Sub Worksheet_Change(ByVal
| Target As Range)" sub? I'm getting what is apparently a compile error
before
| the "new" workbook closes.
|
| I've tried:
|
| x.Remove VBComponent:=x.Item("worksheet").code and several variants of the
| VBComponenet:= thingy without success..
|
| TIA
|
| ABC
|
|


  #3   Report Post  
Posted to microsoft.public.excel.programming
bac bac is offline
external usenet poster
 
Posts: 76
Default Remove VBA code behind a worksheet

Thanx, preciate it!

"Jim Rech" wrote:

With ThisWorkbook.VBProject.VBComponents("Sheet1")
.CodeModule.DeleteLines 1, .CodeModule.CountOfLines
End With


--
Jim
"BAC" wrote in message
...
|I have a worksheet with an event handler:
|
| Private Sub Worksheet_Change(ByVal Target As Range)
| On Error GoTo xitsub
|
| If Target.Address = "$W$7" Then
| After_AIF
|
| Else
|
| End If
| xitsub:
| End Sub
|
| The After_AIF function is in "Module1" which I delete when the workbook is
| saved:
|
| 'Delete VB Code
| Dim x As Object
|
| Set x = Application.VBE.ActiveVBProject.VBComponents
| x.Remove VBComponent:=x.Item("Module1")
|
| My question is how do I delete the "Private Sub Worksheet_Change(ByVal
| Target As Range)" sub? I'm getting what is apparently a compile error
before
| the "new" workbook closes.
|
| I've tried:
|
| x.Remove VBComponent:=x.Item("worksheet").code and several variants of the
| VBComponenet:= thingy without success..
|
| TIA
|
| ABC
|
|



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
remove code from behind worksheet mark kubicki Excel Programming 3 April 28th 05 02:57 PM
Remove / Add code through VBA Sharad Naik Excel Programming 2 December 29th 04 01:16 PM
VBA Code to remove VBA Cory Thomas[_6_] Excel Programming 3 June 9th 04 04:06 PM
Use VB code to remove code in sheet1 WashoeJeff Excel Programming 4 January 25th 04 12:23 AM
Remove VBA code Michi[_2_] Excel Programming 3 January 21st 04 04:18 PM


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