Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Deleting macros with automation

The following function was posted on this site to delete macros:

Const vbext_pk_Proc = 0


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

Set oCodeModule =
ThisWorkbook.VBProject.VBComponents("Module1").Cod eModule
With oCodeModule
On Error GoTo dp_err:
iStart = .ProcStartLine("myProc", vbext_pk_Proc)
cLines = .ProcCountLines("myProc", vbext_pk_Proc)
.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


When I try it out, I get the following error:

Method 'VBProject' of object '_Workbook' failed.

Anyone have a clue about what I'm doing wrong?
Many Thanks!

--
Ray
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Deleting macros with automation

Hi Halray

See this site
http://www.cpearson.com/excel/vbe.htm

Don't forget to set a reference in the VBA to the
Microsoft Visual Basic For Applications Extensibility" library

--
Regards Ron de Bruin
http://www.rondebruin.nl


"Halray" wrote in message ...
The following function was posted on this site to delete macros:

Const vbext_pk_Proc = 0


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

Set oCodeModule =
ThisWorkbook.VBProject.VBComponents("Module1").Cod eModule
With oCodeModule
On Error GoTo dp_err:
iStart = .ProcStartLine("myProc", vbext_pk_Proc)
cLines = .ProcCountLines("myProc", vbext_pk_Proc)
.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


When I try it out, I get the following error:

Method 'VBProject' of object '_Workbook' failed.

Anyone have a clue about what I'm doing wrong?
Many Thanks!

--
Ray



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Deleting macros with automation

Ron,

Thanks for the info - I found what I needed in that link.

Many Thanks Again!!!
--
Ray


"Ron de Bruin" wrote:

Hi Halray

See this site
http://www.cpearson.com/excel/vbe.htm

Don't forget to set a reference in the VBA to the
Microsoft Visual Basic For Applications Extensibility" library

--
Regards Ron de Bruin
http://www.rondebruin.nl


"Halray" wrote in message ...
The following function was posted on this site to delete macros:

Const vbext_pk_Proc = 0


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

Set oCodeModule =
ThisWorkbook.VBProject.VBComponents("Module1").Cod eModule
With oCodeModule
On Error GoTo dp_err:
iStart = .ProcStartLine("myProc", vbext_pk_Proc)
cLines = .ProcCountLines("myProc", vbext_pk_Proc)
.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


When I try it out, I get the following error:

Method 'VBProject' of object '_Workbook' failed.

Anyone have a clue about what I'm doing wrong?
Many Thanks!

--
Ray




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
Deleting Macros T Fuller Excel Discussion (Misc queries) 1 January 13th 06 10:03 PM
Deleting Macros mattflow Excel Discussion (Misc queries) 3 August 23rd 05 07:29 PM
How to use automation Add-In to replace Excel macros!! Abhijit Excel Programming 9 June 3rd 05 03:12 PM
Automation Error when deleting command bar button Frank Kabel Excel Programming 6 August 4th 04 04:09 PM
Outlook Automation, Deleting Tasks jjjustinnn Excel Programming 3 January 17th 04 07:11 PM


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