Worksheets

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

Worksheets
 
Nikita Bodnar




Posts: 20
Joined: 2016-02-22
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: 17113
Joined: 2006-05-11
Hello Nikita,

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

Regards from Belarus (GMT+3),

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




Posts: 20
Joined: 2016-02-22
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: 17113
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.

Regards from Belarus (GMT+3),

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




Posts: 20
Joined: 2016-02-22
Thank you Andrei! It worked.
Posted 01 Nov, 2018 10:05:39 Top