csharp_learner
asked on
Insert text into .doc (with reference)
Hi,
I want to insert some text into a MS word doc template file using C#.
I have followed the code on this website http://support.microsoft.com/kb/316384 but there is a compilation error that oDoc, oMissing and oDoc does not exist in the curent context.
Can any expert help me out here, thanks.
I want to insert some text into a MS word doc template file using C#.
I have followed the code on this website http://support.microsoft.com/kb/316384 but there is a compilation error that oDoc, oMissing and oDoc does not exist in the curent context.
Can any expert help me out here, thanks.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace insertDoc
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
object oTemplate = "C:\\trail.doc";
oDoc = oWord.Documents.Add(ref oTemplate, ref oMissing,ref oMissing, ref oMissing);
object oBookMark = "insert";
oDoc.Bookmarks.Item(ref oBookMark).Range.Text = "Some Text Here";
}
}
}
ASKER
thanks for the prompt reply, i have added the code plus the 2 directories.
But i have 1 single compile error left under oDoc.Bookmarks.Item
'Microsoft.Office.Interop. Word.Bookm arks' does not contain a definition for 'Item' and no extension method 'Item' accepting a first argument of type 'Microsoft.Office.Interop. Word.Bookm arks' could be found
But i have 1 single compile error left under oDoc.Bookmarks.Item
'Microsoft.Office.Interop.
I think you need to use get_Item (as in the example). Some properties take parameters in VBA which isn't possible in C# so they have created new get_... methods.
ASKER
sorry i'm not very good in C# so how can i edit the code to solve the error?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the help and advise.
Open in new window
Also make sure you follow the instructions at the top of the article about adding references to the Word object model