![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
MrExcel MVP
Join Date: Apr 2002
Location: Vancouver BC , Canada
Posts: 6,259
|
Hello Fello xls'ers
I'm having one of those days where I can't see the error for looking . I'm creating a new workbooks , in a macro, with the following workbook.add command... However when I change the code by inserting .sheets=1 I get an error on the code. this works Code:
Set newBook = Workbooks.Add
With newBook
.Title = CurrentTargBkName
.Subject = "Branch Mortgage Summary"
.Comments = "PDR-PVT concept"
.Author = "Nimrod"
.SaveAs Filename:=CurrentTargBkName & ".xls"
End With
Code:
Set newBook = Workbooks.Add
With newBook
.Title = CurrentTargBkName
.Subject = "Branch Mortgage Summary"
.Comments = "PDR concept"
.Author = "Nimrod"
.sheets =1
.SaveAs Filename:=CurrentTargBkName & ".xls"
End With
|
|
|
|
|
|
#2 | |
|
MrExcel MVP
Join Date: Feb 2002
Location: Auckland, New Zealand
Posts: 4,209
|
Quote:
If you are trying to set the Number of sheets in the new workbook ? then you have to reset your current settings for this if it is not 1 eg. Sub Tester() Dim newBook As Workbook Dim OldShcount OldShcount = Application.SheetsInNewWorkbook Application.SheetsInNewWorkbook = 1 Set newBook = Workbooks.Add With newBook .Title = CurrentTargBkName .Subject = "Branch Mortgage Summary" .Comments = "PDR concept" .Author = "Nimrod" .SaveAs Filename:=CurrentTargBkName & ".xls" End With '// Reset it back to your orig setting Application.SheetsInNewWorkbook = OldShcount Set newBook = Nothing End Sub The reason for this is the number of Sheets in the workbook is a property of the Application and not the Workbook. Have a look @ the error generated for the clue to this. |
|
|
|
|
|
|
#3 |
|
MrExcel MVP
Join Date: Apr 2002
Location: Vancouver BC , Canada
Posts: 6,259
|
Thanks Ivan... the problem was really bothering me
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|