Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Macro - New Workbook

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macro - New Workbook


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/sh...d.php?t=180996

Microsoft Office Help

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Macro - New Workbook

The latter worked perfectly.

Really appreciate your help

Cheers



"broro183" wrote:


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/sh...d.php?t=180996

Microsoft Office Help

.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macro - New Workbook


Thanks for the feedback - I'm pleased I could help :-)

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/sh...d.php?t=180996

Microsoft Office Help

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
saving macro from workbook to Personal Macro Workbook KrispyData Excel Discussion (Misc queries) 1 March 25th 10 05:52 PM
Macro to copy specific data from master workbook to another workbook Mark767 Excel Programming 12 September 1st 09 08:57 PM
How do I call up a line of code that references a cell/range in theactive workbook workbook where I am running my macro from? Lav Excel Programming 2 November 11th 08 05:04 PM
Running a macro to protect a workbook on a already protected workbook UNprotects the workbook ?? WimR Excel Programming 9 July 25th 05 12:44 PM
Excel Gurus = want a macro in 1 workbook to get info from another workbook = Read please harry Excel Programming 5 December 20th 03 03:26 AM


All times are GMT +1. The time now is 09:49 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"