Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ASP, Excel, Unable to set the PrintTitleRows property

18 views
Skip to first unread message

xxgeorge

unread,
Jan 9, 2002, 5:50:54 AM1/9/02
to
Hi all,

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!

Mike Musterd

unread,
Jan 9, 2002, 6:32:14 AM1/9/02
to
Works fine with me, straight from VBS.
Only thing I changed was the name of the worksheet (otherwise it would give
'subscript out of range') and modified the 'saveAs' to 'Save'

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

Ada Lam

unread,
Jan 9, 2002, 8:25:26 AM1/9/02
to
Hi Mike,

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!

0 new messages