Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default How To Delete an Excel Macro by Using Automation

We automate Excel (v10) to generate a bunch a workbooks which populate and
format themselves with an imbedded macro. Is there any way to
programmatically delete the macro before distributing the documents?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default How To Delete an Excel Macro by Using Automation

Here is an example to delete a procedure


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



--

HTH

RP
(remove nothere from the email address if mailing direct)


"ScottG" wrote in message
...
We automate Excel (v10) to generate a bunch a workbooks which populate and
format themselves with an imbedded macro. Is there any way to
programmatically delete the macro before distributing the documents?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default How To Delete an Excel Macro by Using Automation

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

should give you a start.

--
Regards,
Tom Ogilvy

"ScottG" wrote in message
...
We automate Excel (v10) to generate a bunch a workbooks which populate and
format themselves with an imbedded macro. Is there any way to
programmatically delete the macro before distributing the documents?



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default How To Delete an Excel Macro by Using Automation

Thanks, that worked perfectly.

Scott

"Bob Phillips" wrote:

Here is an example to delete a procedure


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



--

HTH

RP
(remove nothere from the email address if mailing direct)


"ScottG" wrote in message
...
We automate Excel (v10) to generate a bunch a workbooks which populate and
format themselves with an imbedded macro. Is there any way to
programmatically delete the macro before distributing the documents?




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default How To Delete an Excel Macro by Using Automation


caveat:
when users run those macros they must have a security setting.
"Allow access to Visual Basic Project"

if not your code will fail.

in xl2002 it could be changed via Macro Options by user..
in xl2003 this setting can only be changed with admin priviliges
via registry... in HKLM


--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


ScottG wrote :

Thanks, that worked perfectly.

Scott

"Bob Phillips" wrote:

Here is an example to delete a procedure


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



--

HTH

RP
(remove nothere from the email address if mailing direct)


"ScottG" wrote in message
...
We automate Excel (v10) to generate a bunch a workbooks which
populate and format themselves with an imbedded macro. Is there
any way to programmatically delete the macro before distributing
the documents?






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default How To Delete an Excel Macro by Using Automation

Bob,

I tied the code, but I must be doing soemthing wrong because I get the
following error:

Method 'VBProject' of object '_Workbook' failed.


Can you help me with this? Many Thanks!

Ray Collins


--
Ray


"Bob Phillips" wrote:

Here is an example to delete a procedure


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



--

HTH

RP
(remove nothere from the email address if mailing direct)


"ScottG" wrote in message
...
We automate Excel (v10) to generate a bunch a workbooks which populate and
format themselves with an imbedded macro. Is there any way to
programmatically delete the macro before distributing the documents?




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
Problem with excel macro - getting automation error [email protected] Charts and Charting in Excel 3 October 24th 07 05:22 PM
Disable macro in excel automation with VC++/Win2k mbozzaotre Excel Programming 3 June 14th 05 08:02 PM
How to create a VB macro in Excel from Automation... Cristian Godoci Excel Programming 1 August 5th 04 04:17 PM
Macro 'Automation error' with ChemOffice Excel macro Stew Excel Programming 0 October 27th 03 08:26 PM
access 97 to excel 97: execute macro automation Tom Ogilvy Excel Programming 0 July 13th 03 05:16 PM


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