SonicBoomAu Posted February 15, 2007 Posted February 15, 2007 Hi All, I have started to update one of my programs and have decided i should follow the general rule and turn Option Strict On and Option Explicit On and have come across a problem, which I am hope someone will know the answer for. A sample of my code is as follows: Option Strict On Option Explicit On Imports Microsoft Imports Microsoft.Office Imports Microsoft.Office.Interop ' Start Adding Details to a New Excel Workbook Dim objApp As Excel.Application Dim objBook As Excel._Workbook Dim objBooks As Excel.Workbooks Dim objSheets As Excel.Sheets Dim objSheet As Excel._Worksheet Dim range As Excel.Range Dim PR As DialogResult ' Create a new instance of Excel and start a new workbook. objApp = New Excel.Application objBooks = objApp.Workbooks objBook = objBooks.Add objSheets = objBook.Worksheets objSheet = objSheets(1) objApp.DisplayAlerts = False ' Display only the one sheet not the default three Dim intSheetCount As Integer Dim blnSheetCount As Boolean = False Do Until blnSheetCount = True intSheetCount = objSheets.Count If intSheetCount = 1 Then blnSheetCount = True Else [color="Red"]objBook.Sheets(2).delete()[/color] End If Loop ' Set the page display for the First Page objSheet.Name = "DIntTC Multi Issue" objSheet.PageSetup.Orientation = Excel.XlPageOrientation.xlPortrait objSheet.Range("B2:E2").Merge() objSheet.Range("B2:E2").BorderAround() objSheet.Range("B3:E3").Merge() objSheet.Range("B3:E3").BorderAround() objSheet.Range("B5:E5").Merge() objSheet.Range("B5:E5").BorderAround() [color="red"]objApp.Columns("A").ColumnWidth = "5" objApp.Columns("B").ColumnWidth = "17.57" objApp.Columns("C").ColumnWidth = "24.43" objApp.Columns("D").ColumnWidth = "17.57" objApp.Columns("E").ColumnWidth = "8.43" objApp.Columns("F").ColumnWidth = "5"[/color] ..... ' Exit out of Excel objSheet = Nothing objBook = Nothing objApp.Quit() objApp = Nothing My first problem is on the line "objSheet = objSheets(1)" the error description is: Option Strict On disallows implicit conversions from 'System.Object' to 'Microsoft.Office.Interop.Excel._Worksheet'. The next problem all come up with the description of: Option Strict On Disallows late bindings. I have highlighted the Lines on code that this is effecting. But this problem may be solved with the first problem. I have tried to change the objApp.Coluns to objSheet.Columns and had the same problem. Thank you in advance for your help. Quote Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -- Rick Cook, The Wizardry Compiled
SonicBoomAu Posted February 15, 2007 Author Posted February 15, 2007 I managed to fix the first problem, i think. objSheet = Ctype(objSheet(1), Excel.Worksheet) Quote Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -- Rick Cook, The Wizardry Compiled
Recommended Posts