Invoke code to do a Print area setup in Excel

Hi ,
Could anyone help me with this invoke code where I try to setup activesheet page setup to print area

It looks pagesetup.printarea not seem to work even when I declared Pagesetup

Dim excelapp As Microsoft.Office.Interop.Excel.Application
excelapp = New Microsoft.Office.Interop.Excel.ApplicationClass
Dim workbook As Microsoft.Office.Interop.Excel.Workbook
Dim worksheet As Microsoft.Office.Interop.Excel.Worksheet
excelapp.Visible=True
Dim pagesetup As Microsoft.Office.Interop.Excel.PageSetup
workbook = excelapp.Workbooks.open(path)
worksheet=CType(workbook.Sheets("Sheet1),microsoft.Office.Interop.Excel.Worksheet)
worksheet.Activate

pagesetup.PrintArea = pagesetup.PrintArea
workbook.Save()

Try setting the PrintArea before saving the workbook:

pagesetup = worksheet.PageSetup
pagesetup.PrintArea = "$A$1:$D$10"  Specify the range to be printed
workbook.Save()

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.