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

i have a sheet that runs a macro and then does a save as.

is it possible to delete the macro and command button that launches the
routine before the save as? i didn't think so because the code is still
running.

--


Gary



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 139
Default delete macro question

Gary:

try,

Sub deletecode()
Dim objVBC As Object
Dim objMdl As Object
Dim arr() As Variant
Dim intCounter As Integer
Dim txt As String, fileSaveName As Variant
Dim msg As String
Dim ctl As Shape
'save as
msg = "Save as file"
ChDir ThisWorkbook.Path
fileSaveName = Application.GetSaveAsFilename( _
fileFilter:="Excel Files (*.xls), *.xls", Title:=msg)
If fileSaveName = False Then Exit Sub
Application.ScreenUpdating = False
'delete Sheet1 shape
For Each ctl In Sheet1.Shapes
ctl.Delete
Next ctl
'Star del code
ReDim arr(1 To 3, 1 To ActiveWorkbook.VBProject.VBComponents.Count)
intCounter = 0
For Each objVBC In ActiveWorkbook.VBProject.VBComponents
Set objMdl = objVBC.CodeModule
intCounter = intCounter + 1
arr(1, intCounter) = objVBC.Type
arr(2, intCounter) = objVBC.Name
If objMdl.countoflines 0 Then
txt = objVBC.CodeModule.Lines(1, objMdl.countoflines)
End If
arr(3, intCounter) = txt
Select Case arr(1, intCounter)
Case 1 '(Module)
ActiveWorkbook.VBProject.VBComponents.Remove objVBC
Case 2 ' (Class1)
ActiveWorkbook.VBProject.VBComponents.Remove objVBC
Case 100 ' Thisworkbook
objVBC.CodeModule.DeleteLines 1, objMdl.countoflines
Case 3 'UserForm
ActiveWorkbook.VBProject.VBComponents.Remove objVBC
DoEvents
End Select
Next objVBC
ThisWorkbook.SaveAs fileSaveName
Application.ScreenUpdating = True
End Sub


--
天行健,君*以自強不息
地勢坤,君*以厚德載物

http://www.vba.com.tw/plog/


"Gary Keramidas" wrote:

i have a sheet that runs a macro and then does a save as.

is it possible to delete the macro and command button that launches the
routine before the save as? i didn't think so because the code is still
running.

--


Gary




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default delete macro question

thanks, cj, i'll give it a shot. already have the save routing, just looking
to delete a command button and the macro it runs.


--


Gary


"chijanzen" wrote in message
...
Gary:

try,

Sub deletecode()
Dim objVBC As Object
Dim objMdl As Object
Dim arr() As Variant
Dim intCounter As Integer
Dim txt As String, fileSaveName As Variant
Dim msg As String
Dim ctl As Shape
'save as
msg = "Save as file"
ChDir ThisWorkbook.Path
fileSaveName = Application.GetSaveAsFilename( _
fileFilter:="Excel Files (*.xls), *.xls", Title:=msg)
If fileSaveName = False Then Exit Sub
Application.ScreenUpdating = False
'delete Sheet1 shape
For Each ctl In Sheet1.Shapes
ctl.Delete
Next ctl
'Star del code
ReDim arr(1 To 3, 1 To ActiveWorkbook.VBProject.VBComponents.Count)
intCounter = 0
For Each objVBC In ActiveWorkbook.VBProject.VBComponents
Set objMdl = objVBC.CodeModule
intCounter = intCounter + 1
arr(1, intCounter) = objVBC.Type
arr(2, intCounter) = objVBC.Name
If objMdl.countoflines 0 Then
txt = objVBC.CodeModule.Lines(1, objMdl.countoflines)
End If
arr(3, intCounter) = txt
Select Case arr(1, intCounter)
Case 1 '(Module)
ActiveWorkbook.VBProject.VBComponents.Remove objVBC
Case 2 ' (Class1)
ActiveWorkbook.VBProject.VBComponents.Remove objVBC
Case 100 ' Thisworkbook
objVBC.CodeModule.DeleteLines 1, objMdl.countoflines
Case 3 'UserForm
ActiveWorkbook.VBProject.VBComponents.Remove objVBC
DoEvents
End Select
Next objVBC
ThisWorkbook.SaveAs fileSaveName
Application.ScreenUpdating = True
End Sub


--
???,???????
???,???????

http://www.vba.com.tw/plog/


"Gary Keramidas" wrote:

i have a sheet that runs a macro and then does a save as.

is it possible to delete the macro and command button that launches the
routine before the save as? i didn't think so because the code is still
running.

--


Gary






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 Duplicate Rows Macro Question elfmajesty Excel Discussion (Misc queries) 1 June 17th 06 01:12 AM
Quick Macro question - How to delete two rows then skip one - and repeat David Smithz Excel Discussion (Misc queries) 3 March 3rd 06 02:58 PM
Macro to delete sheets and saves remaining file does not properly delete module bhawane Excel Programming 0 June 21st 05 04:54 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


All times are GMT +1. The time now is 12:34 PM.

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"