Worksheets

Add-in Express™ Support Service
That's what is more important than anything else

Worksheets
 
Nikita Bodnar


Guest


Hello,
I'm trying to create this simple variable:

Excel.Worksheet sheet = ExcelApp.ActiveSheet;

and get an error "Cannot implicitly convert type 'object' to 'Microsoft.Office.Interop.Excel.Worksheet'".

What am I doing wrong?
Posted 01 Nov, 2018 08:36:19 Top
Andrei Smolin


Add-in Express team


Posts: 18793
Joined: 2006-05-11
Hello Nikita,

ExcelApp.ActiveSheet returns an object, not Excel.Worksheet . This is because Excel has several sheet types.


Andrei Smolin
Add-in Express Team Leader
Posted 01 Nov, 2018 09:05:23 Top
Nikita Bodnar


Guest


How do I access the active worksheet?
Could you please give me a code example?
Posted 01 Nov, 2018 09:10:35 Top
Andrei Smolin


Add-in Express team


Posts: 18793
Joined: 2006-05-11
Nikita,

Call ExcelApp.ActiveSheet and cast it to Excel.Worksheet. If the result is null (Nothing in VB), the active sheet is NOT a Worksheet.


Andrei Smolin
Add-in Express Team Leader
Posted 01 Nov, 2018 09:19:35 Top
Nikita Bodnar


Guest


Thank you Andrei! It worked.
Posted 01 Nov, 2018 10:05:39 Top