I've seen similar questions asked, but none that I've found have resolved into a solution for my specific situation.
I have an Excel 2007 COM add-in in Visual Studio 2010, written in C#. When I load the activeworkbook into a workbook object in the ribbon code, it works fine. When I do it in a windows form, it returns null from the activeworkbook every time.
The following are my using statements and the snippet of code where the error keeps happening.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using Office = Microsoft.Office.Core;
using System.Windows.Forms;
using Excel = Microsoft.Office.Interop.Excel;
using System.Drawing;
---------------------------------------------------
Excel.Application xlApp;
xlApp = (Excel.Application)Marshal.GetActiveObject("Excel.Application");
Excel.Workbook xlWkbk = (Excel.Workbook)xlApp.ActiveWorkbook;
Excel.Worksheet xlWksht = (Excel.Worksheet)xlWkbk.ActiveSheet;
Any help would be greatly appreciated!