Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

saving new workbook 1

Status
Not open for further replies.

sedgely

Technical User
Feb 21, 2002
406
GB
I have code that copies the last x number of rows then creates and new workbook and pastes the copied data in. What I need to do is be able to save the new workbook using an already specified variable as the filename. Can I save the new workbook from code in the original workbook?


Cheers, Craig
Si fractum non sit, noli id reficere
 
yes - very much so

Code:
sub example()
dim wbName as string, wb as workbook, strPath as string

wbName = "Test Workbook"
strPath = "C:\Home\"

set wb = workbooks.add
wb.saveas strPath & wbName & ".xls"
end sub

Rgds, Geoff

We could learn a lot from crayons. Some are sharp, some are pretty and some are dull. Some have weird names and all are different colours but they all live in the same box.

Please read FAQ222-2244 before you ask a question
 
Thanks Geoff
That was just what i needed!

Cheers, Craig
Si fractum non sit, noli id reficere
 
Also, to create a workbook with only one sheet in it, use ..

Code:
set wb = workbooks.add(xlWBATWorksheet)

I couldn't find it in any help files, but it's been supported from earlier versions. My fav 'unwritten' tip. :)

-----------
Regards,
Zack Barresse
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top