Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default When recording

I open or "add" a new workbook.

It records fine, but the call to "book7" is hard coded, and in the
future, the code will not be seeing "book7", so how do I call the newly
created workbook by other than its creation name? (I suppose I could
simply name it).
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default When recording

Or use:

ActiveWorkbook

But that only works so long at the new workbook is active. The best thing
is to name the workbook as soon as it is created.

myPath = ThisWorkbook.Path '<<<Change as applicable

Set newBk = Workbooks.Add
'Rename and save the file simultaneously.
newBk.SaveAs = myPath & "\Somename.xls" 'Or xlsx or xlsm, etc.

Workbooks("Somename.xls").Close

"Copacetic" wrote in message
...
I open or "add" a new workbook.

It records fine, but the call to "book7" is hard coded, and in the
future, the code will not be seeing "book7", so how do I call the newly
created workbook by other than its creation name? (I suppose I could
simply name it).



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default When recording

I'd use a variable to represent that newly added workbook.

Dim NewWkbk as workbook
set newwkbk = workbooks.add

Then I could use refer to that workbook whenever I wanted.

newwkbk.worksheets(1).range("a1").value = "hi"

newwkbk.close savechanges:=false



Copacetic wrote:

I open or "add" a new workbook.

It records fine, but the call to "book7" is hard coded, and in the
future, the code will not be seeing "book7", so how do I call the newly
created workbook by other than its creation name? (I suppose I could
simply name it).


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default When recording


Hmmmm... Colonel Clinc say "Vedy interesting..."

I should be able to use this replacement form in a few other
circumstances too. I need to become familiar with this little ghostly
fellow.

Thanks.


On Sat, 01 May 2010 11:26:23 -0500, Dave Peterson
wrote:

I'd use a variable to represent that newly added workbook.

Dim NewWkbk as workbook
set newwkbk = workbooks.add

Then I could use refer to that workbook whenever I wanted.

newwkbk.worksheets(1).range("a1").value = "hi"

newwkbk.close savechanges:=false



Copacetic wrote:

I open or "add" a new workbook.

It records fine, but the call to "book7" is hard coded, and in the
future, the code will not be seeing "book7", so how do I call the newly
created workbook by other than its creation name? (I suppose I could
simply name it).

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
Recording OldManEd Excel Programming 4 September 24th 09 08:32 PM
Recording a macro Denise Payne Excel Programming 4 August 7th 08 10:28 PM
How do I make the Stop Recording bar pop up when recording macros J Excel Worksheet Functions 1 January 10th 06 08:46 PM
Recording changes gibbylinks Excel Discussion (Misc queries) 2 December 5th 05 12:59 PM
recording No Name Excel Programming 2 July 29th 04 02:33 PM


All times are GMT +1. The time now is 12:39 PM.

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

About Us

"It's about Microsoft Excel"