By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,333 Members | 1,060 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,333 IT Pros & Developers. It's quick & easy.

Specified Cast is not Valid

P: n/a
Sorry about the cross-post but I am in a bit of a bind.

I am developing an Add-in for Visio 2002 using VS.NET and I am having
trouble getting a reference to an excel worksheet object that exists on the
page. Here is the code I am having a problem with (doc is declared as
Microsoft.Office.Interop.Visio.Document in the function parameters):
sel = doc.Application.ActiveWindow.Selection '>> Works
obj = sel.Item(1).Object '>> Works
xlSheet = CType(obj, Microsoft.Office.Interop.Excel.WorkSheet) '>>
Throws "Specified Cast is not Valid" exception
MsgBox("Got sheet = " & xlSheet.Name) '>> never gets here
I tried casting to a Workbook object but this did not work either. How can
I get my worksheet object out of the obj variable?
Thanks

Calvin
Nov 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Start by turning OPTION STRICT = ON in your project, then checking the
types. If the types are the same but you are still getting the problem, try
DirectCast instead.

Regards - OHM

calvinX wrote:
Sorry about the cross-post but I am in a bit of a bind.

I am developing an Add-in for Visio 2002 using VS.NET and I am having
trouble getting a reference to an excel worksheet object that exists
on the page. Here is the code I am having a problem with (doc is
declared as Microsoft.Office.Interop.Visio.Document in the function
parameters):
sel = doc.Application.ActiveWindow.Selection '>> Works
obj = sel.Item(1).Object '>>
Works xlSheet = CType(obj, Microsoft.Office.Interop.Excel.WorkSheet)
'>> Throws "Specified Cast is not Valid" exception
MsgBox("Got sheet = " & xlSheet.Name) '>> never gets here
I tried casting to a Workbook object but this did not work either.
How can I get my worksheet object out of the obj variable?
Thanks

Calvin


--
Best Regards - OHM

O_H_M{at}BTInternet{dot}com
Nov 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.