Learning from a Visual Studio Tools for Office book

John 506 Reputation points
2023-05-24T14:04:18.1633333+00:00

I have a book titled, "Visual Studio Tools for Office", but it was published in 2006.

So many changes may have been made to the VSTO framework since then.

Here is an example out of this book.

It is in a class file, but it will not sense correctly.

Which returning type of class would I need to make it work, and would I need to do these in an Add-in, workbook, or template for VSTO?

using Excel = Microsoft.Office.Interop.Excel;

class SampleListener
{
	private Excel.Application app;
	
	public SampleListener(Excel.Application application)
	{
		app = application
	}

	public void ConnectEvents()
	{
		app.WorkbookOpen += new AppEvents_WorkbookOpenEventHandler(this.MyOpenHandler);
	}

	public void DisconnectEvents()
	{
		
		app.WorkbookOpen -= new AppEvents_WorkbookOpenEventHandler(this.MyOpenHandler);

	}

	public void MyOpenHandler(Excel.Workbook workbook)
	{
		MessageBox.Show(String.Format("{0}" was opened. ", workbook.Name);
	}

}
Microsoft 365 and Office | Development | Other
Microsoft 365 and Office | Word | For business | Windows
Microsoft 365 and Office | Excel | For business | Windows
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.