0

I am writing a VTSO application that should work across multiple excel document templates. I want the add in to check the document and attempt to select the one the user is using, however I cannot figure out how to grab the current filename in c# using VTSO

Julius Alexander
  • 431
  • 2
  • 6
  • 13

1 Answers1

0

Try this example:

using System;
using Excel = Microsoft.Office.Interop.Excel;

namespace Foo
{
    class Program
    {
        static void Main(string[] args)
        {
            var excelApplication = (Excel.Application)CustomMarshal.GetActiveObject("Excel.Application");
            var currentWorkbook = excelApplication.ActiveWorkbook;
            Console.WriteLine("Current active Excel Workbook: " + currentWorkbook.Name); // or FullName to get full path to opened file
            Console.ReadKey();
        }
    }
}

CustomMarshal and GetActiveObject() explanations can be found here: No definition found for GetActiveObject from System.Runtime.InteropServices.Marshal C#

Auditive
  • 1,607
  • 1
  • 7
  • 13