-1

Why is wb a null object?

What am I doing wrong?

Excel.Application ap = (Excel.Application)Marshal.GetActiveObject("Excel.Application");
Excel.Workbook wb = ap.ActiveWorkbook;
Excel.Worksheet ws = ap.ActiveSheet;
grishin
  • 31
  • 3
  • What does this have to do with the VSTO technology? Or Excel Add-ins? A more appropriate tag might be office-interop... – Cindy Meister Jan 29 '18 at 14:39
  • Are there any workbooks open in the currently running instance of Excel? What does ap.Workbooks.Count return? – Cindy Meister Jan 29 '18 at 14:40
  • Interop.Excel. Yes, it's addin work in open excel. Workbook opened. Yesterday I just closed the studio. Today I open, I launch and voila. Working. I do not know, apparently bugs in the studio. It's sad. I lost the evening. Yesterday I recompiled and did not do anything. I knew that I should work. Previously, it worked. That's all it was decided. Thank's man. – grishin Jan 29 '18 at 17:43
  • I do not understand why I was neglected ... Cruel people from the IT world. – grishin Jan 29 '18 at 17:45

2 Answers2

0

The bug of VS. Today start and it work. Magic.

grishin
  • 31
  • 3
0

The bug of VS. Today start and it work. Magic. Today it all worked again, but not for long. Marshaling began to catch a book in which the sheets are defaulted. Replaced all this miracle by Globals.Addins ...

grishin
  • 31
  • 3