Becks25Not
Programmer
Hi All,
I have a form with an OWC9 Spreadsheet control. I build an Excel Report in the control then export it. I have to open it and do some final formatting that I can't do in the OWC control.
My problem is, if the form with the OWC control & Excel object is open, Excel doesn't work. It sorts of opens but never comes up then gives a refrenced memory exception. If I close the form, I have no problem. It's not the OEC control b/c I commented out the creating of the Excel Object and didn't have the problem. Any help would be greatly appreciated!!
Here is my code to do the final formatting of Excel:
Thanks!!
Becca
I have a form with an OWC9 Spreadsheet control. I build an Excel Report in the control then export it. I have to open it and do some final formatting that I can't do in the OWC control.
My problem is, if the form with the OWC control & Excel object is open, Excel doesn't work. It sorts of opens but never comes up then gives a refrenced memory exception. If I close the form, I have no problem. It's not the OEC control b/c I commented out the creating of the Excel Object and didn't have the problem. Any help would be greatly appreciated!!
Here is my code to do the final formatting of Excel:
Code:
Dim xlsApp As Excel.Application
xlsApp = CType(CreateObject("Excel.Application"), Excel.Application)
Dim wb As Excel.Workbook = xlsApp.Workbooks.Open(Me.strFullName)
Dim sh As Excel.Worksheet = wb.Worksheets.Item("Sheet1")
With sh
Dim r As Excel.Range = sh.Cells.Range("L4")
With r
.WrapText = True
End With
.PageSetup.Orientation = Excel.XlPageOrientation.xlLandscape
.PageSetup.PrintGridlines = False
.PageSetup.Zoom = False
.PageSetup.FitToPagesWide = 1
.PageSetup.FitToPagesTall = 100
.PageSetup.CenterFooter = "Page : (&P of &N)"
.PageSetup.LeftMargin = xlsApp.InchesToPoints(0.35)
.PageSetup.RightMargin = xlsApp.InchesToPoints(0.35)
.PageSetup.TopMargin = xlsApp.InchesToPoints(0.35)
.PageSetup.BottomMargin = xlsApp.InchesToPoints(0.5)
.PageSetup.HeaderMargin = xlsApp.InchesToPoints(0.25)
.PageSetup.FooterMargin = xlsApp.InchesToPoints(0.25)
End With
wb.Save()
wb.Close()
xlsApp.Quit()
sh = Nothing
wb = Nothing
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlsApp)
xlsApp = Nothing
GC.Collect()
Thanks!!
Becca