Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Delete Code from Worksheet

I have a workbook with a button that copies itself to a
new workbook. I then delete the button from the new
workbook but the code remains. In the VBA Editor I can
see the code attached to the worksheet.

Is there a way to delete the code or perhaps copy the
worksheet from the original workbook without the button
and associated code?

Thanks,
JohnV
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Delete Code from Worksheet

Stolen from Chip Pearson's site:
http://www.cpearson.com/excel/vbe.htm

Option Explicit
Sub DeleteAllVBA()

Dim VBComp As VBIDE.VBComponent

With ActiveWorkbook
Set VBComp = .VBProject.VBComponents(.Worksheets("sheet1").Code Name)
End With
With VBComp.CodeModule
.DeleteLines 1, .CountOfLines
End With
End Sub


JohnV wrote:

I have a workbook with a button that copies itself to a
new workbook. I then delete the button from the new
workbook but the code remains. In the VBA Editor I can
see the code attached to the worksheet.

Is there a way to delete the code or perhaps copy the
worksheet from the original workbook without the button
and associated code?

Thanks,
JohnV


--

Dave Peterson

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default Delete Code from Worksheet

Try the following code experimentally. The code has not
been tested in the scenario you describe.

Assumptions:
1) The workbook that needs code deletion is the active
workbook.
2) The code module containing the code pertains to the
active sheet.
3) There are 5 code lines for the button.

Dim CM As Object, StartLine As Integer
With Application.VBE.ActiveVBProject
Set CM = .VBComponents(ActiveSheet.CodeName).CodeModule
StartLine = CM.CountOfLines + 1
.VBComponents(ActiveSheet.CodeName).CodeModule _
.DeleteLines StartLine, 5
End With

Regards,
Greg

-----Original Message-----
I have a workbook with a button that copies itself to a
new workbook. I then delete the button from the new
workbook but the code remains. In the VBA Editor I can
see the code attached to the worksheet.

Is there a way to delete the code or perhaps copy the
worksheet from the original workbook without the button
and associated code?

Thanks,
JohnV
.

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
Delete object code Marie Bayes Excel Discussion (Misc queries) 1 April 29th 09 03:41 PM
Delete code chrisnsmith Excel Discussion (Misc queries) 4 March 8th 09 01:10 AM
delete code keeps going and coing Wanna Learn Excel Discussion (Misc queries) 5 September 2nd 08 11:02 PM
How to code to insert / delete any worksheet? Eric Excel Worksheet Functions 1 March 2nd 08 10:02 PM
VBA code to delete rows Secret Squirrel Excel Discussion (Misc queries) 3 January 21st 07 03:01 PM


All times are GMT +1. The time now is 04:11 PM.

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"