Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,388
Default Macro to delete macro?

I have a workbook_open macro included in the global workbook object
("ThisWorkbook"). This currently calls a macro to run upon opening the
workbook, after which the module "Self-destructs" by deleting itself, but I'm
still left with the workbook_open code so people get that "This workbook
contains macros..." popup when they open the sheet. Is there a way for this
module to also clear the workbook_open code located in "ThisWorkbook"?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 110
Default Macro to delete macro?

Hi Dave
Use this code below, it will clear all code from your workbook:
Dim VBC As VBComponent
With ActiveWorkbook.VBProject
For Each VBC In .VBComponents
If VBC.Type = 100 Then
With VBC.CodeModule
.DeleteLines 1, .CountOfLines
.CodePane.Window.Close
End With
Else: .VBComponents.Remove VBC
End If
Next VBC
End With

HTH
Cordially
Pascal

"Dave" a écrit dans le message de news:
...
I have a workbook_open macro included in the global workbook object
("ThisWorkbook"). This currently calls a macro to run upon opening the
workbook, after which the module "Self-destructs" by deleting itself, but
I'm
still left with the workbook_open code so people get that "This workbook
contains macros..." popup when they open the sheet. Is there a way for
this
module to also clear the workbook_open code located in "ThisWorkbook"?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,388
Default Macro to delete macro?

Papou,
It seems to not like the "Dim VBC as VBComponent" line, I get the following
error:

Compile error:
User-defined type not defined

Any suggestions?

"papou" wrote:

Hi Dave
Use this code below, it will clear all code from your workbook:
Dim VBC As VBComponent
With ActiveWorkbook.VBProject
For Each VBC In .VBComponents
If VBC.Type = 100 Then
With VBC.CodeModule
.DeleteLines 1, .CountOfLines
.CodePane.Window.Close
End With
Else: .VBComponents.Remove VBC
End If
Next VBC
End With

HTH
Cordially
Pascal

"Dave" a écrit dans le message de news:
...
I have a workbook_open macro included in the global workbook object
("ThisWorkbook"). This currently calls a macro to run upon opening the
workbook, after which the module "Self-destructs" by deleting itself, but
I'm
still left with the workbook_open code so people get that "This workbook
contains macros..." popup when they open the sheet. Is there a way for
this
module to also clear the workbook_open code located in "ThisWorkbook"?




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,388
Default Macro to delete macro?

Got it, I had to change the declaration of "VBC" to an Object and it worked:

Dim VBC As Object
With ActiveWorkbook.VBProject
For Each VBC In .VBComponents
If VBC.Type = 100 Then
With VBC.CodeModule
.DeleteLines 1, .CountOfLines
.CodePane.Window.Close
End With
Else: .VBComponents.Remove VBC
End If
Next VBC
End With



"Dave" wrote:

Papou,
It seems to not like the "Dim VBC as VBComponent" line, I get the following
error:

Compile error:
User-defined type not defined

Any suggestions?

"papou" wrote:

Hi Dave
Use this code below, it will clear all code from your workbook:
Dim VBC As VBComponent
With ActiveWorkbook.VBProject
For Each VBC In .VBComponents
If VBC.Type = 100 Then
With VBC.CodeModule
.DeleteLines 1, .CountOfLines
.CodePane.Window.Close
End With
Else: .VBComponents.Remove VBC
End If
Next VBC
End With

HTH
Cordially
Pascal

"Dave" a écrit dans le message de news:
...
I have a workbook_open macro included in the global workbook object
("ThisWorkbook"). This currently calls a macro to run upon opening the
workbook, after which the module "Self-destructs" by deleting itself, but
I'm
still left with the workbook_open code so people get that "This workbook
contains macros..." popup when they open the sheet. Is there a way for
this
module to also clear the workbook_open code located in "ThisWorkbook"?




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 110
Default Macro to delete macro?

Dave
Sorry for this late reply.
Yes you may as well use an Object declaration.
But the other alternative which I forgot to mention was to add a reference
to
"Microsoft Visual Basic For Application Extensibility 5.3"
And in which case the original code would work.

Cordially
Pascal

"Dave" a écrit dans le message de news:
...
Got it, I had to change the declaration of "VBC" to an Object and it
worked:

Dim VBC As Object
With ActiveWorkbook.VBProject
For Each VBC In .VBComponents
If VBC.Type = 100 Then
With VBC.CodeModule
.DeleteLines 1, .CountOfLines
.CodePane.Window.Close
End With
Else: .VBComponents.Remove VBC
End If
Next VBC
End With



"Dave" wrote:

Papou,
It seems to not like the "Dim VBC as VBComponent" line, I get the
following
error:

Compile error:
User-defined type not defined

Any suggestions?

"papou" wrote:

Hi Dave
Use this code below, it will clear all code from your workbook:
Dim VBC As VBComponent
With ActiveWorkbook.VBProject
For Each VBC In .VBComponents
If VBC.Type = 100 Then
With VBC.CodeModule
.DeleteLines 1, .CountOfLines
.CodePane.Window.Close
End With
Else: .VBComponents.Remove VBC
End If
Next VBC
End With

HTH
Cordially
Pascal

"Dave" a écrit dans le message de
news:
...
I have a workbook_open macro included in the global workbook object
("ThisWorkbook"). This currently calls a macro to run upon opening
the
workbook, after which the module "Self-destructs" by deleting itself,
but
I'm
still left with the workbook_open code so people get that "This
workbook
contains macros..." popup when they open the sheet. Is there a way
for
this
module to also clear the workbook_open code located in
"ThisWorkbook"?





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
Macro to delete sheets and saves remaining file does not properly delete module pherrero Excel Programming 0 June 21st 05 05:11 PM
Macro to delete sheets and saves remaining file does not properly delete module bhawane Excel Programming 0 June 21st 05 04:53 PM
Macro to delete sheets and saves remaining file does not properly delete module pherrero Excel Programming 0 June 21st 05 04:38 PM
Macro to delete sheets and saves remaining file does not properly delete module bhawane Excel Programming 0 June 21st 05 04:20 PM
macro to delete entire rows when column A is blank ...a quick macro vikram Excel Programming 4 May 3rd 04 08:45 PM


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