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

I have an auto_open macro on a workbook that performs some functions, then
does a save as with today's date as the file name. The problem is that the
new file has the auto_open macro in it too, and when I open it, the macro
runs. I would like to put some code in to prevent the macros being saved
with the new sheet, or in some way delete the auto-open before it saves. Any
ideas would be welcome.

Regards

Alan
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 112
Default Macro to delete a macro

Hello Alan

Place the code into your auto_open macro below your last instructions and
amend accordingly (Module name):

Dim MyModule
Set MyModule = ThisWorkbook.VBProject.VBComponents("Module2")
ThisWorkbook.VBProject.VBComponents.Remove MyModule

HTH
Cordially
Pascal



"Alan B" <Alan a écrit dans le message de news:
...
I have an auto_open macro on a workbook that performs some functions, then
does a save as with today's date as the file name. The problem is that
the
new file has the auto_open macro in it too, and when I open it, the macro
runs. I would like to put some code in to prevent the macros being saved
with the new sheet, or in some way delete the auto-open before it saves.
Any
ideas would be welcome.

Regards

Alan



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Macro to delete a macro

Pascal,

Thank you for your response. I have created a second Macro called sub
delandsave() which contains the following code:

Sub delandsave()
'
'Deletes auto_open
'
Dim MyModule
Set MyModule = ThisWorkbook.VBProject.VBComponents("Auto_Open")
ThisWorkbook.VBProject.VBComponents.Remove MyModule
'
'Creates new workbook using date in DATA worksheet cell AG1 as name
'
Dim SaveName As String
SaveName = Sheets("query").Range("ag1").Text
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:="\\colorado\Impromptu\finance\Stock Sheets\"
& SaveName & ".xls"

End Sub

This is called from the auto_open, and should delete the auto_open macro.
When I run it, I keep getting an error on the "Set MyModule =.." line.

Any ideas?

Regards

ALan Berry

"papou" wrote:

Alan
You may also need to amend security settings:
From the Excel spreadsheet menu:
Tools, Macro, Security
Approved Editors tab (please note caption may vary, I have a french version
of Excel)
Tick "Trust Visual Basic Project"
Click OK and save your workbook

HTH
Cordially
Pascal

"papou" a écrit dans le message de news:
...
Hello Alan

Place the code into your auto_open macro below your last instructions and
amend accordingly (Module name):

Dim MyModule
Set MyModule = ThisWorkbook.VBProject.VBComponents("Module2")
ThisWorkbook.VBProject.VBComponents.Remove MyModule

HTH
Cordially
Pascal



"Alan B" <Alan
a écrit dans le message de
news:
...
I have an auto_open macro on a workbook that performs some functions, then
does a save as with today's date as the file name. The problem is that
the
new file has the auto_open macro in it too, and when I open it, the macro
runs. I would like to put some code in to prevent the macros being saved
with the new sheet, or in some way delete the auto-open before it saves.
Any
ideas would be welcome.

Regards

Alan






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Macro to delete a macro

Do you have a module named Auto_Open? If you do, you shouldn't.

I believe papou assumed you had a separate module (don't have procedures and
modules with the same name) that contained only the Auto_Open procedure.

--
Regards,
Tom Ogilvy


"Alan B" wrote:

Pascal,

Thank you for your response. I have created a second Macro called sub
delandsave() which contains the following code:

Sub delandsave()
'
'Deletes auto_open
'
Dim MyModule
Set MyModule = ThisWorkbook.VBProject.VBComponents("Auto_Open")
ThisWorkbook.VBProject.VBComponents.Remove MyModule
'
'Creates new workbook using date in DATA worksheet cell AG1 as name
'
Dim SaveName As String
SaveName = Sheets("query").Range("ag1").Text
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:="\\colorado\Impromptu\finance\Stock Sheets\"
& SaveName & ".xls"

End Sub

This is called from the auto_open, and should delete the auto_open macro.
When I run it, I keep getting an error on the "Set MyModule =.." line.

Any ideas?

Regards

ALan Berry

"papou" wrote:

Alan
You may also need to amend security settings:
From the Excel spreadsheet menu:
Tools, Macro, Security
Approved Editors tab (please note caption may vary, I have a french version
of Excel)
Tick "Trust Visual Basic Project"
Click OK and save your workbook

HTH
Cordially
Pascal

"papou" a écrit dans le message de news:
...
Hello Alan

Place the code into your auto_open macro below your last instructions and
amend accordingly (Module name):

Dim MyModule
Set MyModule = ThisWorkbook.VBProject.VBComponents("Module2")
ThisWorkbook.VBProject.VBComponents.Remove MyModule

HTH
Cordially
Pascal



"Alan B" <Alan
a écrit dans le message de
news:
...
I have an auto_open macro on a workbook that performs some functions, then
does a save as with today's date as the file name. The problem is that
the
new file has the auto_open macro in it too, and when I open it, the macro
runs. I would like to put some code in to prevent the macros being saved
with the new sheet, or in some way delete the auto-open before it saves.
Any
ideas would be welcome.

Regards

Alan







  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 112
Default Macro to delete a macro

Hello Alan
You should place the code in your auto_open macro and NOT in a seperate
macro.
As mentionned Tom in his post, your module should NOT have the same name as
your macro.
My sample works for a module named "Module2", this name should be amended to
reflect your module name (and NOT macro name).
The module name appears in the Modules folder from the VBAproject tree of
your workbook, available in the VBA editor.

HTH
Cordially
Pascal

"Alan B" a écrit dans le message de news:
...
Pascal,

Thank you for your response. I have created a second Macro called sub
delandsave() which contains the following code:

Sub delandsave()
'
'Deletes auto_open
'
Dim MyModule
Set MyModule = ThisWorkbook.VBProject.VBComponents("Auto_Open")
ThisWorkbook.VBProject.VBComponents.Remove MyModule
'
'Creates new workbook using date in DATA worksheet cell AG1 as name
'
Dim SaveName As String
SaveName = Sheets("query").Range("ag1").Text
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:="\\colorado\Impromptu\finance\Stock
Sheets\"
& SaveName & ".xls"

End Sub

This is called from the auto_open, and should delete the auto_open macro.
When I run it, I keep getting an error on the "Set MyModule =.." line.

Any ideas?

Regards

ALan Berry

"papou" wrote:

Alan
You may also need to amend security settings:
From the Excel spreadsheet menu:
Tools, Macro, Security
Approved Editors tab (please note caption may vary, I have a french
version
of Excel)
Tick "Trust Visual Basic Project"
Click OK and save your workbook

HTH
Cordially
Pascal

"papou" a écrit dans le message de
news:
...
Hello Alan

Place the code into your auto_open macro below your last instructions
and
amend accordingly (Module name):

Dim MyModule
Set MyModule = ThisWorkbook.VBProject.VBComponents("Module2")
ThisWorkbook.VBProject.VBComponents.Remove MyModule

HTH
Cordially
Pascal



"Alan B" <Alan
a écrit dans le message de
news:
...
I have an auto_open macro on a workbook that performs some functions,
then
does a save as with today's date as the file name. The problem is
that
the
new file has the auto_open macro in it too, and when I open it, the
macro
runs. I would like to put some code in to prevent the macros being
saved
with the new sheet, or in some way delete the auto-open before it
saves.
Any
ideas would be welcome.

Regards

Alan







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 1 June 22nd 05 01:12 AM
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 bhawane Excel Programming 0 June 21st 05 04:53 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:04 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"