ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   After Workbook.Add (https://www.excelbanter.com/excel-discussion-misc-queries/221539-after-workbook-add.html)

chrisnsmith

After Workbook.Add
 
I use the following macro I created with the macro recorder to add a new
workbook
without vb code for emailing. What I need to know is how to give a name to
this workbook after it is created. Help would be appreciated.

Workbooks.Add

Windows("Form 200").Activate
Sheets(Array("Cus Futures", "House Futures", "Cus Calls", "Cus Puts", _
"House Options", "Cus Indexes")).Select
Sheets("Cus Futures").Activate
Sheets(Array("Cus Futures", "House Futures", "Cus Calls", "Cus Puts", _
"House Options", "Cus Indexes")).Copy Befo=Workbooks("Book2").Sheets(1)


eksh

After Workbook.Add
 
you need to use save as method i.e.
ActiveWorkbook.SaveAs ("Filename")

"chrisnsmith" wrote:

I use the following macro I created with the macro recorder to add a new
workbook
without vb code for emailing. What I need to know is how to give a name to
this workbook after it is created. Help would be appreciated.

Workbooks.Add

Windows("Form 200").Activate
Sheets(Array("Cus Futures", "House Futures", "Cus Calls", "Cus Puts", _
"House Options", "Cus Indexes")).Select
Sheets("Cus Futures").Activate
Sheets(Array("Cus Futures", "House Futures", "Cus Calls", "Cus Puts", _
"House Options", "Cus Indexes")).Copy Befo=Workbooks("Book2").Sheets(1)


JLatham

After Workbook.Add
 
chrisnsmith -
to add to what eksh said ... put the line of code he provided right after
your
Workbooks.Add statement before coming back to the primary workbook. You
will also need to change the name of the workbook from "Book2" down in the
final statement you posted here. Might consider using a variable to build up
a new name, this code would take the current workbook's name and add a date
stamp to it to use as the filename. Code could look something like this:

Dim newFileName As String

newFileName = Left(ThisWorkbook.Name, _
InStrRev(ThisWorkbook.Name, ".") - 1)
newFileName = newFileName & "_" & _
Format(Year(Now()), "0000") & "_" & _
Format(Month(Now()), "00") & "_" & _
Format(Day(Now()), "00") & ".xls"

Workbooks.Add
ActiveWorkbook.SaveAs newFileName

Windows("Form 200").Activate
Sheets(Array("Cus Futures", "House Futures", "Cus Calls", "Cus Puts", _
"House Options", "Cus Indexes")).Select
Sheets("Cus Futures").Activate
Sheets(Array("Cus Futures", "House Futures", "Cus Calls", "Cus Puts", _
"House Options", "Cus Indexes")).Copy _
Befo=Workbooks(newFileName).Sheets(1)

"eksh" wrote:

you need to use save as method i.e.
ActiveWorkbook.SaveAs ("Filename")

"chrisnsmith" wrote:

I use the following macro I created with the macro recorder to add a new
workbook
without vb code for emailing. What I need to know is how to give a name to
this workbook after it is created. Help would be appreciated.

Workbooks.Add

Windows("Form 200").Activate
Sheets(Array("Cus Futures", "House Futures", "Cus Calls", "Cus Puts", _
"House Options", "Cus Indexes")).Select
Sheets("Cus Futures").Activate
Sheets(Array("Cus Futures", "House Futures", "Cus Calls", "Cus Puts", _
"House Options", "Cus Indexes")).Copy Befo=Workbooks("Book2").Sheets(1)



All times are GMT +1. The time now is 02:04 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com