Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

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

Posted

I managed to fix the first problem, i think.

 


objSheet = Ctype(objSheet(1), Excel.Worksheet)

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

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...