Temp work sheets, then do..

cfer

Well-known Member
Joined
Jul 29, 2002
Messages
560
Hi,

I have a Workbook, works well with a lot of Macros. I want it to a little more now, with what I want to do, I will need to undo the calculations again after the new macro runs.

I was thinking if I could have a Macro that would save Sheet A and Sheet B to a new file, do what I need, then delete the Temp file, without user intervention.

Any ideas on what sort of code I would need.

Thanks in advance.

Cfer
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Code:
Set tmpbk = Workbooks.Add
Sheets("sheet A").Copy tmpbk.Sheets(1)
Sheets("sheet B").Copy tmpbk.Sheets(1)
'much other code
tmpbk.Close savechange:=False
set tmpbk = nothing
you should set sheet object for the sheets you want to work with so there is no confusion with sheet names, remember to destroy all objects
 
Upvote 0
Hi westconn1,

Thanks for the reply.

I get an error each time, it seems to create a file with a new number each time.
ie Book5, then when run Book6 so on.

Any ideas, as it does not create a file called tmpbk

Thans again..

Cfer
 
Upvote 0
tmpbk would be an object representing the new workbook, whatever the name of the workbook is, as the tmbk is never saved it never has a proper name, just bookX starting from book1 each time excel starts

if you put a breakpoint in the code then in the immediate window type
?tmpbk.name
should print
book?

of course as the book opens and closes you never see the result unless you stop the code part way
 
Upvote 0

Forum statistics

Threads
1,222,195
Messages
6,164,513
Members
451,900
Latest member
lamski

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
Back
Top