When developing an application that uses data in an Office document, it might be beneficial to have that data presented directly within your Visual Basic application so that the user can see and edit the data without having to switch to the Office application. You can accomplish this in Visual Basic using the Edraw Office Viewer Component.

This article demonstrates how to dynamically create and Automate the Word, Excel or PowerPoint document using the Office Viwer Component.

1. Create a new Visual Baisc application. 

2. From the Project Menu select Components…

2. Select control “Edraw Office Viewer Component” in the controls table

3. Click the OK Button

4.  The control will now appear in your toolbox

5.   Drag and drop the control on your form

The control also supports a property called Dispatch that allows you to obtain a reference to the IDispatch interface of the embedded object. From this interface you can automate the object to perform tasks, edit parts of the document, or gather information about what a user has added or removed. For example, if you have a Word document open, you can use code that resembles the following to add a line of text.

OfficeViewer1.CreateNew “Word.Document”

Set objWord = OfficeViewer1.ActiveDocument

objWord.Content.Text = “This was added by Automation”