PC Review


Reply
Thread Tools Rate Thread

Delete VB code from a worksheet

 
 
Henk
Guest
Posts: n/a
 
      28th May 2009
Within a Worksheet_Change macro on sheet A, I copy sheet A to Sheet A (2).
Directly after that, I want to remove all VB code from Sheet A (2).

How do I do that?

Thanks in advance,

Henk

 
Reply With Quote
 
 
 
 
Henk
Guest
Posts: n/a
 
      28th May 2009
Joel,

Thanks for your prompt reply. I had been there before and after my visit I
manged to delete Modules and Forms from my VBA projects, but now I want to
delete all code from a specific Worksheet. Chip does not tell how to do that.
Any idea?

Regards,

Henk

"Joel" wrote:

> Go to chip pearson website.
>
> http://www.cpearson.com/Excel/vbe.aspx
>
>
>
> "Henk" wrote:
>
> > Within a Worksheet_Change macro on sheet A, I copy sheet A to Sheet A (2).
> > Directly after that, I want to remove all VB code from Sheet A (2).
> >
> > How do I do that?
> >
> > Thanks in advance,
> >
> > Henk
> >

 
Reply With Quote
 
Joel
Guest
Posts: n/a
 
      28th May 2009
I modified slight some of chips code. This clears sheet1 code.


Sub DeleteProcedureFromModule()
Dim VBProj As VBIDE.VBProject
Dim VBComp As VBIDE.VBComponent
Dim CodeMod As VBIDE.CodeModule
Dim StartLine As Long
Dim NumLines As Long
Dim ProcName As String

Set VBProj = ActiveWorkbook.VBProject
Set VBComp = VBProj.VBComponents("Sheet1")
Set CodeMod = VBComp.CodeModule


With CodeMod
.DeleteLines StartLine:=1, Count:=.CountOfLines
End With
End Sub


"Henk" wrote:

> Joel,
>
> Thanks for your prompt reply. I had been there before and after my visit I
> manged to delete Modules and Forms from my VBA projects, but now I want to
> delete all code from a specific Worksheet. Chip does not tell how to do that.
> Any idea?
>
> Regards,
>
> Henk
>
> "Joel" wrote:
>
> > Go to chip pearson website.
> >
> > http://www.cpearson.com/Excel/vbe.aspx
> >
> >
> >
> > "Henk" wrote:
> >
> > > Within a Worksheet_Change macro on sheet A, I copy sheet A to Sheet A (2).
> > > Directly after that, I want to remove all VB code from Sheet A (2).
> > >
> > > How do I do that?
> > >
> > > Thanks in advance,
> > >
> > > Henk
> > >

 
Reply With Quote
 
Henk
Guest
Posts: n/a
 
      28th May 2009
Joel,

I embedded tho code you sent me in my code. When I start the code I get the
message :

"Excel has stopped working"
"Windows is checking for a solution to this problem" :

After a little while :

"Microsoft Office Excel is trying to recover your information"
"This might take a few minutes"

After another little while :

"Microsoft Excel is restarting"

And then my file opens again. With the new sheet and ...... without the VB
code.

So, somehow it works but not the way it should, I think.

Another thing is that I now know that the new sheet is called Sheet2,
because I can see that in VB. But how do I know the name when a second copy
or third is made, by someone else on another PC? Can I ask for the name of
the new sheet in VB?

I am struggling further. Hope you can struggle with me.

Kind regards,

Henk



"Joel" wrote:

> I modified slight some of chips code. This clears sheet1 code.
>
>
> Sub DeleteProcedureFromModule()
> Dim VBProj As VBIDE.VBProject
> Dim VBComp As VBIDE.VBComponent
> Dim CodeMod As VBIDE.CodeModule
> Dim StartLine As Long
> Dim NumLines As Long
> Dim ProcName As String
>
> Set VBProj = ActiveWorkbook.VBProject
> Set VBComp = VBProj.VBComponents("Sheet1")
> Set CodeMod = VBComp.CodeModule
>
>
> With CodeMod
> .DeleteLines StartLine:=1, Count:=.CountOfLines
> End With
> End Sub
>
>
> "Henk" wrote:
>
> > Joel,
> >
> > Thanks for your prompt reply. I had been there before and after my visit I
> > manged to delete Modules and Forms from my VBA projects, but now I want to
> > delete all code from a specific Worksheet. Chip does not tell how to do that.
> > Any idea?
> >
> > Regards,
> >
> > Henk
> >
> > "Joel" wrote:
> >
> > > Go to chip pearson website.
> > >
> > > http://www.cpearson.com/Excel/vbe.aspx
> > >
> > >
> > >
> > > "Henk" wrote:
> > >
> > > > Within a Worksheet_Change macro on sheet A, I copy sheet A to Sheet A (2).
> > > > Directly after that, I want to remove all VB code from Sheet A (2).
> > > >
> > > > How do I do that?
> > > >
> > > > Thanks in advance,
> > > >
> > > > Henk
> > > >

 
Reply With Quote
 
Joel
Guest
Posts: n/a
 
      28th May 2009
if you are trying to delete specific subroutine by name of subroutine you can
go through the enire workbook project and search for thsoe macro by name.
Do you want users to insert there own macros into the workbook? Do you want
the user macros also to be deleted?

I don't put my macros on thisworkbook and sheets unless it is an event
macro. All my macros go into modules. I'm not sure what macros you are
trying to delte from the sheets. You may want to delete all macro from the
sheets and leave the macros in the module alone.

"Henk" wrote:

> Joel,
>
> I embedded tho code you sent me in my code. When I start the code I get the
> message :
>
> "Excel has stopped working"
> "Windows is checking for a solution to this problem" :
>
> After a little while :
>
> "Microsoft Office Excel is trying to recover your information"
> "This might take a few minutes"
>
> After another little while :
>
> "Microsoft Excel is restarting"
>
> And then my file opens again. With the new sheet and ...... without the VB
> code.
>
> So, somehow it works but not the way it should, I think.
>
> Another thing is that I now know that the new sheet is called Sheet2,
> because I can see that in VB. But how do I know the name when a second copy
> or third is made, by someone else on another PC? Can I ask for the name of
> the new sheet in VB?
>
> I am struggling further. Hope you can struggle with me.
>
> Kind regards,
>
> Henk
>
>
>
> "Joel" wrote:
>
> > I modified slight some of chips code. This clears sheet1 code.
> >
> >
> > Sub DeleteProcedureFromModule()
> > Dim VBProj As VBIDE.VBProject
> > Dim VBComp As VBIDE.VBComponent
> > Dim CodeMod As VBIDE.CodeModule
> > Dim StartLine As Long
> > Dim NumLines As Long
> > Dim ProcName As String
> >
> > Set VBProj = ActiveWorkbook.VBProject
> > Set VBComp = VBProj.VBComponents("Sheet1")
> > Set CodeMod = VBComp.CodeModule
> >
> >
> > With CodeMod
> > .DeleteLines StartLine:=1, Count:=.CountOfLines
> > End With
> > End Sub
> >
> >
> > "Henk" wrote:
> >
> > > Joel,
> > >
> > > Thanks for your prompt reply. I had been there before and after my visit I
> > > manged to delete Modules and Forms from my VBA projects, but now I want to
> > > delete all code from a specific Worksheet. Chip does not tell how to do that.
> > > Any idea?
> > >
> > > Regards,
> > >
> > > Henk
> > >
> > > "Joel" wrote:
> > >
> > > > Go to chip pearson website.
> > > >
> > > > http://www.cpearson.com/Excel/vbe.aspx
> > > >
> > > >
> > > >
> > > > "Henk" wrote:
> > > >
> > > > > Within a Worksheet_Change macro on sheet A, I copy sheet A to Sheet A (2).
> > > > > Directly after that, I want to remove all VB code from Sheet A (2).
> > > > >
> > > > > How do I do that?
> > > > >
> > > > > Thanks in advance,
> > > > >
> > > > > Henk
> > > > >

 
Reply With Quote
 
Henk
Guest
Posts: n/a
 
      28th May 2009
Joel,

It is a Change_Worksheet macro ons Sheet A that copies itself to sheet A
(2), which therefor has the same Change_Worksheet event macro, which is
started when I change something on Sheet A (2). So I think I will choose for
an "elegant" workaround by enabling events only when thes Sheet.Name = Sheet
A. So the code remains on Sheet A (2), but it will never be invoked.

Many thanks for your help. It's very much appreciated.

Regards,

Henk


"Joel" wrote:

> if you are trying to delete specific subroutine by name of subroutine you can
> go through the enire workbook project and search for thsoe macro by name.
> Do you want users to insert there own macros into the workbook? Do you want
> the user macros also to be deleted?
>
> I don't put my macros on thisworkbook and sheets unless it is an event
> macro. All my macros go into modules. I'm not sure what macros you are
> trying to delte from the sheets. You may want to delete all macro from the
> sheets and leave the macros in the module alone.
>
> "Henk" wrote:
>
> > Joel,
> >
> > I embedded tho code you sent me in my code. When I start the code I get the
> > message :
> >
> > "Excel has stopped working"
> > "Windows is checking for a solution to this problem" :
> >
> > After a little while :
> >
> > "Microsoft Office Excel is trying to recover your information"
> > "This might take a few minutes"
> >
> > After another little while :
> >
> > "Microsoft Excel is restarting"
> >
> > And then my file opens again. With the new sheet and ...... without the VB
> > code.
> >
> > So, somehow it works but not the way it should, I think.
> >
> > Another thing is that I now know that the new sheet is called Sheet2,
> > because I can see that in VB. But how do I know the name when a second copy
> > or third is made, by someone else on another PC? Can I ask for the name of
> > the new sheet in VB?
> >
> > I am struggling further. Hope you can struggle with me.
> >
> > Kind regards,
> >
> > Henk
> >
> >
> >
> > "Joel" wrote:
> >
> > > I modified slight some of chips code. This clears sheet1 code.
> > >
> > >
> > > Sub DeleteProcedureFromModule()
> > > Dim VBProj As VBIDE.VBProject
> > > Dim VBComp As VBIDE.VBComponent
> > > Dim CodeMod As VBIDE.CodeModule
> > > Dim StartLine As Long
> > > Dim NumLines As Long
> > > Dim ProcName As String
> > >
> > > Set VBProj = ActiveWorkbook.VBProject
> > > Set VBComp = VBProj.VBComponents("Sheet1")
> > > Set CodeMod = VBComp.CodeModule
> > >
> > >
> > > With CodeMod
> > > .DeleteLines StartLine:=1, Count:=.CountOfLines
> > > End With
> > > End Sub
> > >
> > >
> > > "Henk" wrote:
> > >
> > > > Joel,
> > > >
> > > > Thanks for your prompt reply. I had been there before and after my visit I
> > > > manged to delete Modules and Forms from my VBA projects, but now I want to
> > > > delete all code from a specific Worksheet. Chip does not tell how to do that.
> > > > Any idea?
> > > >
> > > > Regards,
> > > >
> > > > Henk
> > > >
> > > > "Joel" wrote:
> > > >
> > > > > Go to chip pearson website.
> > > > >
> > > > > http://www.cpearson.com/Excel/vbe.aspx
> > > > >
> > > > >
> > > > >
> > > > > "Henk" wrote:
> > > > >
> > > > > > Within a Worksheet_Change macro on sheet A, I copy sheet A to Sheet A (2).
> > > > > > Directly after that, I want to remove all VB code from Sheet A (2).
> > > > > >
> > > > > > How do I do that?
> > > > > >
> > > > > > Thanks in advance,
> > > > > >
> > > > > > Henk
> > > > > >

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
RE: Delete VB code from a worksheet Joel Microsoft Excel Programming 0 28th May 2009 12:12 PM
How to code to insert / delete any worksheet? Eric Microsoft Excel Worksheet Functions 1 2nd Mar 2008 10:02 PM
Re: Delete VBA code in worksheet through a macro Chip Pearson Microsoft Excel Programming 1 23rd Jul 2004 09:35 AM
Re: Delete VBA code in worksheet through a macro Ken Wright Microsoft Excel Programming 0 22nd Jul 2004 08:59 PM
Delete Code from Worksheet JohnV Microsoft Excel Programming 2 13th Sep 2003 03:56 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:13 PM.