Skip to Main Content
Visual Studio Hacks
book

Visual Studio Hacks

by James Avery
March 2005
Intermediate to advanced content levelIntermediate to advanced
304 pages
19h 23m
English
O'Reilly Media, Inc.
Content preview from Visual Studio Hacks
374
|
Chapter 11, Visual Studio Tools for Office
#85 Display a Windows Form from Excel 2003
HACK
Next, you need to create a SqlConnection, SqlCommand, and SqlDataReader to
retrieve the data from the database. Once you have retrieved the record, you
will output the records to the
Word.Selection variable that you created ear-
lier using the
TypeText method.
Now that you have created the method to output the data record to your
Word document, you need to wire that code into the button by attaching
the delegate to your event handler:
private void WireUpEvents( )
{
// Set up the Click events for the command bar buttons.
CBarButtonEvent =
new Office._CommandBarButtonEvents_ClickEventHandler
(CBarButton_Click);
CBarButton.Click += CBarButtonEvent;
}
One last order of business is to finish the document initialization process by
updating the
ThisDocument_New method to call the event wire-up code after
the command bar has been created:
protected void ThisDocument_New( )
{
SetupCommandBar( );
WireUpEvents( );
}
Now, build and test the application once again. This time, when you click
the button on the command bar, the name and address for the customer will
be typed into the Word document.
—Brian Sherwin
HACK
#85
Display a Windows Form from Excel 2003 Hack #85
Create a graphical application to gather information for Excel.
In this hack, you’ll learn how to make an Excel workbook pop up a Win-
dows Form application to collect ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Microsoft Visual Studio 2015 Unleashed, Third Edition

Microsoft Visual Studio 2015 Unleashed, Third Edition

Mike Snell, Lars Powers
.Net Framework Essentials

.Net Framework Essentials

Thuan L. Thai, Hoang Lam
C# 5.0 Unleashed

C# 5.0 Unleashed

Bart De Smet
Programming .NET Security

Programming .NET Security

Adam Freeman, Allen Jones

Publisher Resources

ISBN: 0596008473Errata Page