Word program with c#

http://www.c-sharpcorner.com/UploadFile/amrish_deep/WordAutomation05102007223934PM/WordAutomation.aspx

7. Embedding a Document:

Embedding a document is done through the application by

Insert-> Object-> Create from file-> Select the File-> Display as Icon. This embeds the file in the selected location as an icon and the user can double click on the icon to open the file. The same can be done through automation.

The range supposed to set at the required place and the same has to be selected (range can be set by any of the means mentioned above). Now with the selection, the file can be embedded.

//ICON LABEL CAN BE THE NAME OF THE FILE,

//ITS THE NAME DISPLAYED BESIDES THE EMBEDDED DOCUMENT

Object oIconLabel = “File Name”;

//INCASE WE NEED THE EMBEDDED DOCUMENT TO BE DISPLAYED AS A SPECIFIC ICON,

//WE NEED TO SPECIFY THE LOCATION OF THE ICON FILE

//ELSE SET IT TO oMissing VALUE

Object oIconFileName = “C:\\Document and Settings\\IconFile.ico”;

//THE BOOKMARK WHERE THE FILE NEEDS TO BE EMBEDDED

Object oBookMark = “My_Custom_BookMark”;

//THE LOCATION OF THE FILE

Object oFileDesignInfo = “C:\\Document and Settings\\somefile.doc”;

//OTHER VARIABLES

Object oClassType = “Word.Document.8”;

Object oTrue = true;

Object oFalse = false;

Object oMissing = System.Reflection.Missing.Value;

//METHOD TO EMBED THE DOCUMENT

oWordDoc.Bookmarks.get_Item(ref oBookMark).Range.InlineShapes.AddOLEObject(

ref oClassType,ref oFileDesignInfo,ref oFalse, ref oTrue, ref oIconFileName,

ref oMissing,ref oIconLabel, ref oMissing);

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s