Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 168
Default Using a macro to remove a macro

I have this macro (below) that I would like to remove using another macro.
It is located in 'ThisWorkbook'.

Private Sub Workbook_Open()

What code can I use in a Macro to remove 'Private Sub Workbook_Open()'?

Thanks,
Paul


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default Using a macro to remove a macro

'----------------------------------------------------------------
Sub DeleteProcedure()
'----------------------------------------------------------------
Dim oCodeModule As Object
Dim iStart As Long
Dim cLines As Long

Set oCodeModule =
ThisWorkbook.VBProject.VBComponents("ThisWorkbook" ).CodeModule
With oCodeModule
On Error GoTo dp_err:
iStart = .ProcStartLine("Workbook_Open", 0)
cLines = .ProcCountLines("Workbook_Open", 0)
.DeleteLines iStart, cLines
On Error GoTo 0
Exit Sub
End With

dp_err:
If Err.Number = 35 Then
MsgBox "Procedure does not exist"
End If
End Sub



--
HTH

Bob Phillips

"PCLIVE" wrote in message
...
I have this macro (below) that I would like to remove using another macro.
It is located in 'ThisWorkbook'.

Private Sub Workbook_Open()

What code can I use in a Macro to remove 'Private Sub Workbook_Open()'?

Thanks,
Paul




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 168
Default Using a macro to remove a macro

Thanks Bob. You're right-on!
I really appreciate it.

Regards,
Paul

"Bob Phillips" wrote in message
...
'----------------------------------------------------------------
Sub DeleteProcedure()
'----------------------------------------------------------------
Dim oCodeModule As Object
Dim iStart As Long
Dim cLines As Long

Set oCodeModule =
ThisWorkbook.VBProject.VBComponents("ThisWorkbook" ).CodeModule
With oCodeModule
On Error GoTo dp_err:
iStart = .ProcStartLine("Workbook_Open", 0)
cLines = .ProcCountLines("Workbook_Open", 0)
.DeleteLines iStart, cLines
On Error GoTo 0
Exit Sub
End With

dp_err:
If Err.Number = 35 Then
MsgBox "Procedure does not exist"
End If
End Sub



--
HTH

Bob Phillips

"PCLIVE" wrote in message
...
I have this macro (below) that I would like to remove using another
macro.
It is located in 'ThisWorkbook'.

Private Sub Workbook_Open()

What code can I use in a Macro to remove 'Private Sub Workbook_Open()'?

Thanks,
Paul






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default Using a macro to remove a macro

See Chip Pearson's site for info on this subject.

http://www.cpearson.com/excel/vbe.htm


Gord Dibben Excel MVP

On Fri, 1 Jul 2005 14:24:42 -0400, "PCLIVE" wrote:

I have this macro (below) that I would like to remove using another macro.
It is located in 'ThisWorkbook'.

Private Sub Workbook_Open()

What code can I use in a Macro to remove 'Private Sub Workbook_Open()'?

Thanks,
Paul


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 a Macro stew Excel Discussion (Misc queries) 2 November 8th 08 02:03 AM
Macro - Remove #n/a Schwimms Excel Discussion (Misc queries) 3 February 14th 08 06:29 PM
macro 4.remove D. Excel Discussion (Misc queries) 2 September 29th 07 02:52 PM
Macro to Remove Macro Text Rob Excel Discussion (Misc queries) 1 June 21st 07 11:49 PM
remove macro Ron New Users to Excel 2 June 1st 06 02:57 PM


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