Macro - New Workbook

G

Goaliemenace

I have a macro that opens a new workbook and creates 120 tabs of information,
everything process correctly works perfectly only when run for the first
time. The issue is when i run the macro again, Excel now opens "book2" The
macro then stops as it is set for Book 1. Can this variable be adjusted for

Cells.Select
Selection.Copy
Windows("book1").Activate

This is where it runs all the subsequent part of the macro from. The macro
before this opens up a new work book with the tab settings then it grabs the
required info and copies it and then goes to the workbook.

Please help

Cheers
 
B

broro183

hi Goaliemenace

Here are two examples of how you can set a variable to be a workbook
The first is when you open an existing file & the second is if you ar
create a file...



VBA Code:
--------------------


Option Explicit
Sub Macro2()
Dim Createdwb As Workbook
Set Createdwb = Workbooks.Open(Filename:="blah.xls")
'or
Set Createdwb = Workbooks.Add
'other code, eg...
Createdwb.activate
'free memory
Set Createdwb = Nothing
End Sub

--------------------




hth
Rob
 
G

Goaliemenace

The latter worked perfectly.

Really appreciate your help

Cheers



broro183 said:
hi Goaliemenace

Here are two examples of how you can set a variable to be a workbook.
The first is when you open an existing file & the second is if you are
create a file...
VBA Code:
Option Explicit
Sub Macro2()
Dim Createdwb As Workbook
Set Createdwb = Workbooks.Open(Filename:="blah.xls")
'or
Set Createdwb = Workbooks.Add
'other code, eg...
Createdwb.activate
'free memory
Set Createdwb = Nothing
End Sub
--------------------




hth
Rob


--
broro183

Rob Brockett. Always learning & the best way to learn is to
experience...
------------------------------------------------------------------------
broro183's Profile: 333
View this thread: http://www.thecodecage.com/forumz/showthread.php?t=180996

Microsoft Office Help

.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top