copying a module

cbennetts

New Member
Joined
Feb 23, 2004
Messages
29
Good Day all.
Here is the deal, I have a workbook which is called HM2005Nov23 that does automatic queries to the net every second. That runs just fine. When I get an error though (ie 1004) I want it to clone itself (modules and all) into another book that is titled the same but with a .1, .2, .3 etc. depending on how many times it has had to clone itself. After it clones itself I want it to delete the old version of itself and then start the web query again. Any suggestions?

Chet
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.

Oorang

Well-known Member
Joined
Mar 4, 2005
Messages
2,071
Just use thisworkbook.saveas
Then delete the old file with Kill
 

cbennetts

New Member
Joined
Feb 23, 2004
Messages
29
By using the aforementioned kill, will that completly delete the old file?
 

cbennetts

New Member
Joined
Feb 23, 2004
Messages
29

ADVERTISEMENT

Sounds like exactly what I want to do. Would it look something like this:

Sub kill()
'
'Other applicable code
'
Workbooks("try to kill").kill
'
'Other applicable code
'
End Sub
 

HalfAce

MrExcel MVP
Joined
Apr 6, 2003
Messages
9,456
If you're using SaveAs to create a new copy of the workbook, the module will get saved in the new workbook also. There shouldn't be a need for exporting/importing the module itself.

BTW, I didn't ignore your PM. When I tried using the relevent code to export/import Module1 between a couple workbooks, Norton freaked out. Said I had a Bloodhound virus named "ExcelMacro". Had a bit of a time getting rid of those two workbooks.
(Now Norton is happy again.)
 

cbennetts

New Member
Joined
Feb 23, 2004
Messages
29
That is the same problem I had too. Interesting. I will try the save as instead. Thanks and Happy Turkey Day!

Chet
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,998
Messages
5,834,805
Members
430,322
Latest member
excelnoobnoob

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top