E
educos
Hi everybody,
Does anyone know why the printarea of pagesetup is not restored when opening
an Excel file through automation using workbook.open method.
To reproduce the case:
First step:
1. create a new Excel file in Excel 2007
2. Define a print area
3. Save the file and close Excel.
Second step:
1. In VisualStudio, create a small program, add a reference to Microsoft
Excel 12 Object library
2. write the following lines:
Dim xlsApp As Excel.Application = New Excel.Application
xlsApp.Visible = True
Dim wkb As Excel.Workbook = xlsApp.Workbooks.Open("MyFile.xlsx")
Dim wks As Excel.Worksheet = wkb.ActiveSheet
MessageBox.Show(wks.PageSetup.PrintArea)
wkb.Close()
xlsApp.Quit()
3. Surprise: the PrintArea is empty.
4. If you set a breakpoint after opening the file and go in Excel to look at
Page Setup, the PrintArea is also empty.
5. Is you open the fiile again with Excel and go to Page Setup you can look
again at the print area you have defined intialy
Well....what is the secret ???? What is missing when opening the Excel file
through automation ?
Regards..
Does anyone know why the printarea of pagesetup is not restored when opening
an Excel file through automation using workbook.open method.
To reproduce the case:
First step:
1. create a new Excel file in Excel 2007
2. Define a print area
3. Save the file and close Excel.
Second step:
1. In VisualStudio, create a small program, add a reference to Microsoft
Excel 12 Object library
2. write the following lines:
Dim xlsApp As Excel.Application = New Excel.Application
xlsApp.Visible = True
Dim wkb As Excel.Workbook = xlsApp.Workbooks.Open("MyFile.xlsx")
Dim wks As Excel.Worksheet = wkb.ActiveSheet
MessageBox.Show(wks.PageSetup.PrintArea)
wkb.Close()
xlsApp.Quit()
3. Surprise: the PrintArea is empty.
4. If you set a breakpoint after opening the file and go in Excel to look at
Page Setup, the PrintArea is also empty.
5. Is you open the fiile again with Excel and go to Page Setup you can look
again at the print area you have defined intialy
Well....what is the secret ???? What is missing when opening the Excel file
through automation ?
Regards..