Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27254

VS 2013 Excel.Interop and late binding problem

$
0
0
I have a functional program that reads a few cells from and Excel worksheet but with option strict I get an error that "Option Strict On disallows late binding." In the past I disabled option strict as a workaround but today I wanted to do it right. Imports Microsoft.Office.Interop.
vb.net Code:
  1. Dim excel As Excel.Application
  2. Dim ewb As Excel.Workbook = excel.Workbooks.Open("A:\myfile.xlsx")
  3. Dim ews As Excel.Worksheet = CType(ewb.Worksheets.Item("Main"), Excel.Worksheet)
Why does removing the CType generate the error? Isn't Worksheets.items() of the type Excel.Worksheet?

Interestingly I read this perfect article on the MSDN so I created a new sub and pasted it in. It too ends up with the error. And it's supposed to demonstrate how to use early binding to avoid this error. What am I doing wrong?

Viewing all articles
Browse latest Browse all 27254

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>