Microsoft Office Tutorials and References
In Depth Information
The workbook host item
// Visual Studio generated
this.Startup += new System.EventHandler(ThisWorkbook_Startup);
this.Shutdown += new System.EventHandler(ThisWorkbook_
Shutdown);
}
// NewWorkbook event in the Excel solution
public void ThisWorkbook_NewWorkbook(Microsoft.Office.
Interop.Excel.Workbook AuthorWorkBook)
{
// Reading from Excel using the Range object
Excel.Range AuthorRange = Globals.Sheet1.Range["B1", "D5"] as
Excel.Range;
// Formatting the selected Range with autocolor format
AuthorRange.AutoFormat(Excel.XlRangeAutoFormat.
xlRangeAutoFormatClassic3, true, false, true, false, true,
true);
// Messagebox after range of cells formatted
MessageBox.Show("New workbook name: " + AuthorWorkBook.Name);
}
Now, let's see the WorkbookOpen event of the workbook host item. Here, let's
register the WorkbookOpen event in the workbook solution.
private void InternalStartup()
{
// Explicitly cast the application object to the application
events
((Excel.AppEvents_Event)ThisApplication).WorkbookOpen += new
Microsoft.Office.Interop.Excel.
AppEvents_WorkbookOpenEventHandler(ThisWorkbook_WorkbookOpen);
// Visual Studio generated
this.Startup += new System.EventHandler(ThisWorkbook_Startup);
this.Shutdown += new System.EventHandler(ThisWorkbook_
Shutdown);
}
// Open event of Workbook
public void ThisWorkbook_WorkbookOpen(Microsoft.Office.
Interop.Excel.Workbook AuthorWorkBook)
{
// Messagebox shows the name of the file being opened
MessageBox.Show("You are opening workbook name: " +
AuthorWorkBook.Name);
}
 
Search JabSto ::




Custom Search