I'm trying to create an excel spreadsheet via an ASP page. I'm able
to
create the spreadsheet just fine, but I got errors when adding codes
to set the pagesetup properties. But I can run the same script at
Excel's macro. Why?
I'm running IIS 5.0, IE 5.0, Excel 2000, and there is a
printer installed on the web server, so the pagesetup properties
SHOULD
be available.
Sample ASP Code:
....
....
Set objExcelApp = Server.CreateObject("Excel.Application")
objExcelApp.Application.Visible = False
Set objEWorkBook = objExcelApp.Workbooks.Open("abc.xls")
objExcelApp.DisplayAlerts = False
objEWorkBook.Activate
Set objEWorkSheet = objEWorkBook.Worksheets("Sheet1")
'pageSetup start
objEWorkSheet.PageSetup.PrintTitleRows = _
objEWorkSheet.Rows("1").Address
objExcelApp.ActiveSheet.PageSetup.PrintTitleColumns = _
objEWorkSheet.Columns("A:B").Address
'pageSetup end
objEWorkBook.SaveAs "abc.xls"
objExcelApp.DisplayAlerts = True
'--- Clean up
On Error Resume Next
objEWorkBook.Close
objExcelApp.Workbooks.close
objExcelApp.Quit
Set objEWorkSheet = Nothing
Set objEWorkBook = Nothing
Set objExcelApp = Nothing
...
...
But errors occur:
Unable to set the PrintTitleRows property of the PageSetup class
Thanks for your help!
So I don't know...
Mike
Sub AddNewPageSetupToExcel(FileName)
Set objExcelApp = CreateObject("Excel.Application")
Set objEWorkBook = objExcelApp.Workbooks.Open(FileName)
objExcelApp.DisplayAlerts = False
objEWorkBook.Activate
objExcelApp.Application.Visible = True
Set objEWorkSheet = objEWorkBook.Worksheets("Prospects")
'pageSetup start
objEWorkSheet.PageSetup.PrintTitleRows = _
objEWorkSheet.Rows("1").Address
objEWorkSheet.PageSetup.PrintTitleColumns = _
objEWorkSheet.Columns("A:B").Address
'pageSetup end
objEWorkBook.Save
objExcelApp.DisplayAlerts = True
'--- Clean up
On Error Resume Next
objEWorkBook.Close
objExcelApp.Workbooks.close
objExcelApp.Quit
Set objEWorkSheet = Nothing
Set objEWorkBook = Nothing
Set objExcelApp = Nothing
End Sub
I have the same problem as xxgeorge. I can run the code in Macro, but
failed in ASP program with the same error message. Are you running the
program in ASP page? If yes, how can you do that? Please help!
Thanks!
Ada ^o^
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!