
Learning from a Visual Studio Tools for Office book
John
506
Reputation points
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

4,394 questions
Microsoft 365 and Office | Word | For business | Windows

2,008 questions
Microsoft 365 and Office | Excel | For business | Windows

3,967 questions
Sign in to answer