I'm not a scripter/programmer, just know how to cut and paste really
well. I need some eyes to tell me what I am doing wrong with this
script that I am trying to use to create a spreadsheet named
(currentdate) and with 18 additional worksheets added to the three
that are already created.
I found a script that does part of what I want, but I am having
trouble creating the other worksheets within the workbook....
Can someone show me the correct syntax or what I am doing wrong?
Thanks;
dtmDate = Date
strMonth = Month(Date)
strDay = Day(Date)
strYear = Right(Year(Date),2)
strFileName = "R:\xyz\weeklyreports\addedrules\" & strMonth & "-" &
strDay & "-" & strYear & ".xls"
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objWorkbook = objExcel.Workbooks.Add()
Sheets.Add
Sheets.Add
Sheets.Add
Sheets.Add
Sheets.Add
Sheets.Add
Sheets.Add
Sheets.Add
Sheets.Add
Sheets.Add
Sheets.Add
Sheets.Add
Sheets.Add
Sheets.Add
Sheets.Add
Sheets.Add
Sheets.Add
Sheets.Add
Sheets.Add
objWorkbook.SaveAs(strFileName)
' Try this
Const xlWorksheet = -4167
objWorkbook.Sheets.Add xlWorksheet, 19
> objWorkbook.SaveAs(strFileName)
Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/
I tried this but got the error add method of Sheets class failed. The
code I am now using is below:
dtmDate = Date
strMonth = Month(Date)
strDay = Day(Date)
strYear = Right(Year(Date),2)
strFileName = "R:\NETIQ\weeklyreports\addedrules\" & strMonth & "-" &
strDay & "-" & strYear & ".xls"
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objWorkbook = objExcel.Workbooks.Add()
Const xlWorksheet = -4167
objWorkbook.Sheets.Add xlWorksheet, 19
objWorkbook.SaveAs(strFileName)
Hello,
thanks for the suggestion; however, with the new code i get the
following error:
800A0009 - Subscript out of range...
**code**
dtmDate = Date
strMonth = Month(Date)
strDay = Day(Date)
strYear = Right(Year(Date),2)
strFileName = "R:\NETIQ\weeklyreports\addedrules\" & strMonth & "-" &
strDay & "-" & strYear & ".xls"
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objWorkbook = objExcel.Workbooks.Add()
objWorkbook.Sheets.Add ,objWorkbook.Sheets(4),19
objWorkbook.SaveAs(strFileName)
If objExcel.Workbooks.Add() creates a workbook with three worksheets, then
there is no objWorkbook.Sheets(4). You could try using
objWorkbook.Sheets.Count instead:
dtmDate = Date
strMonth = Month(Date)
strDay = Day(Date)
strYear = Right(Year(Date),2)
strFileName = "c:\scripts\" & strMonth & "-" & strDay & "-" & strYear &
".xls"
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objWorkbook = objExcel.Workbooks.Add()
objWorkbook.Sheets.Add ,objWorkbook.Sheets(objWorkbook.Sheets.Count),19
objWorkbook.SaveAs(strFileName)
--
urkec
Good catch.
Thanks,
Thank you to both urkec and Tom; the last change worked urkec and the
final code is:
******************************************
dtmDate = Date
strMonth = Month(Date)
strDay = Day(Date)
strYear = Right(Year(Date),2)
strFileName = "R:\NETIQ\weeklyreports\addedrules\" & strMonth & "-" &
strDay & "-" & strYear & ".xls"
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objWorkbook = objExcel.Workbooks.Add()
objWorkbook.Sheets.Add ,objWorkbook.Sheets(objWorkbook.Sheets.Count),
19
objWorkbook.SaveAs(strFileName)
*******************************************
Thank you again!