Problem with Excel and Option Strict On

SonicBoomAu

Well-known member
Joined
Oct 30, 2003
Messages
179
Location
Australia
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:

[VB]
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
objBook.Sheets(2).delete()
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()
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"


.....

Exit out of Excel
objSheet = Nothing
objBook = Nothing
objApp.Quit()
objApp = Nothing

[/VB]

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.
 
Back
Top