Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default How do I direct a macro to a newly opened workbook

A Macro in my MasterFile.XLS opens a New Workbook and pastes a copy of one of
the sheets into the new workbook. I want to then return to MasterFile.xls,
clear contents in cell C6 of the Input page and then return to the newly
created workbook.

Whilst in the abbreviated coding below, the new book is Book12, it could of
course be any number depending on how many times I run the process in the
course of the day. After creating the new workbook, it gets saved with a name
so there is only ever one new workbook open at a time but with a variable
number.

How do I achieve this ?

Cells.Select
Selection.Copy

Workbooks.Add Template:="Workbook"
Cells.Select
ActiveSheet.Paste

Windows("MasterFile.xls").Activate
Sheets("Input Page").Select
Range("C6").Select
Application.CutCopyMode = False
Selection.ClearContents


Windows("Book12").Activate
Range("F31").Select

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default How do I direct a macro to a newly opened workbook

Something like this should do

dim wbkNew as workbook

set wbknew = Workbooks.Add Template:="Workbook"

thisworkbook.Sheets("Sheet1").Cells.copy Destination:= _
wbknew.sheets("Sheet1").Cells

thisworkbook.Sheets("Input Page").Range("C6").ClearContents

Range("F31").Select

--
HTH...

Jim Thomlinson


"dave caizley" wrote:

A Macro in my MasterFile.XLS opens a New Workbook and pastes a copy of one of
the sheets into the new workbook. I want to then return to MasterFile.xls,
clear contents in cell C6 of the Input page and then return to the newly
created workbook.

Whilst in the abbreviated coding below, the new book is Book12, it could of
course be any number depending on how many times I run the process in the
course of the day. After creating the new workbook, it gets saved with a name
so there is only ever one new workbook open at a time but with a variable
number.

How do I achieve this ?

Cells.Select
Selection.Copy

Workbooks.Add Template:="Workbook"
Cells.Select
ActiveSheet.Paste

Windows("MasterFile.xls").Activate
Sheets("Input Page").Select
Range("C6").Select
Application.CutCopyMode = False
Selection.ClearContents


Windows("Book12").Activate
Range("F31").Select

End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default How do I direct a macro to a newly opened workbook

Right after:
Workbooks.Add Template:="Workbook"
insert the line:

s = ActiveWorkbook.Name


and then instead of:
Windows("Book12").Activate
use:

Windows(s).Activate


This works because after you Add the new workbook, it becomes the Active
workbook and we set the variable s to remember its name.
--
Gary''s Student - gsnu200773


"dave caizley" wrote:

A Macro in my MasterFile.XLS opens a New Workbook and pastes a copy of one of
the sheets into the new workbook. I want to then return to MasterFile.xls,
clear contents in cell C6 of the Input page and then return to the newly
created workbook.

Whilst in the abbreviated coding below, the new book is Book12, it could of
course be any number depending on how many times I run the process in the
course of the day. After creating the new workbook, it gets saved with a name
so there is only ever one new workbook open at a time but with a variable
number.

How do I achieve this ?

Cells.Select
Selection.Copy

Workbooks.Add Template:="Workbook"
Cells.Select
ActiveSheet.Paste

Windows("MasterFile.xls").Activate
Sheets("Input Page").Select
Range("C6").Select
Application.CutCopyMode = False
Selection.ClearContents


Windows("Book12").Activate
Range("F31").Select

End Sub

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
Newly opened spreadsheet doesn't display in Excel 2007 kwdavids Excel Discussion (Misc queries) 2 June 19th 08 04:39 PM
Allow user to choose worksheet from newly opened file Chris Lewis[_2_] Excel Programming 2 October 3rd 06 12:14 PM
Close file and run macro from newly opened file Pradip Jain Excel Programming 1 April 23rd 05 11:39 PM
can't save newly opened files Rasoul Khoshravan Excel Discussion (Misc queries) 1 December 9th 04 07:27 AM
Run a macro when a workbook is opened Mervyn Thomas[_3_] Excel Programming 0 July 25th 03 11:18 AM


All times are GMT +1. The time now is 06:22 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"