Accessing a checkbox in Word

Dec 6 2009 4:09 PM

Hi all,
 
I have a program that needs to access a word document (2003)So far, I can open the file, place text in certain locations in a table, and save the file based on date and time created.  I need to be able to either click or unclick several checkboxes based on information from a WPF form.  I have included the code I have so far for your viewing pleasure.
 
Thanks in advance.
 
private void CreateWordFile()
{
DateTime myDate;
object oMissing = System.Reflection.Missing.Value;
object oEndOfDoc = "\\endofdoc"; //\endofdoc is a predifined bookmark.
//Start Word and open template.
Word.
_Application oWord;
Word.
_Document oDoc;
oWord =
new Word.Application();
oWord.Visible =
true;
object fileName = @"C:\Plant Tracker\AMP-108_old.doc";
oDoc = oWord.Documents.Open(
ref fileName, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);

//Create Bookmarks.
object oBookMark = "FacNameBkMk";
oDoc.Bookmarks.get_Item(
ref oBookMark).Range.Text = "Magnolia Energy";
oBookMark =
"EventDateBkMk";
myDate =
Convert.ToDateTime(eventDateTxtBx.Text);
oDoc.Bookmarks.get_Item(
ref oBookMark).Range.Text = myDate.ToShortDateString().ToString();
oBookMark =
"EventNumBkMk";
oDoc.Bookmarks.get_Item(
ref oBookMark).Range.Text = eventNoTxtBx.Text;
oBookMark =
"TitleBkMk";
oDoc.Bookmarks.get_Item(
ref oBookMark).Range.Text = titleTxtBx.Text;
oBookMark =
"SummaryBkMk";
oDoc.Bookmarks.get_Item(
ref oBookMark).Range.Text = summaryTxtBx.Text;
oBookMark =
"DetailBkMk";
oDoc.Bookmarks.get_Item(
ref oBookMark).Range.Text = detailTxtBx.Text;
oBookMark =
"RespBkMk";
oDoc.Bookmarks.get_Item(
ref oBookMark).Range.Text = caRespTxtBx.Text;
oBookMark =
"CADueBkMk";
myDate =
Convert.ToDateTime(caDueDateTxtBx.Text);
oDoc.Bookmarks.get_Item(
ref oBookMark).Range.Text = myDate.ToShortDateString().ToString();
oBookMark =
"CorrActBkMk";
oDoc.Bookmarks.get_Item(
ref oBookMark).Range.Text = corrActionTxtBx.Text;
oBookMark =
"PrepByBkMk";
oDoc.Bookmarks.get_Item(
ref oBookMark).Range.Text = prepByTxtBx.Text;
oBookMark =
"PrepDateBkMk";
myDate =
Convert.ToDateTime(prepDateTxtBx.Text);
oDoc.Bookmarks.get_Item(
ref oBookMark).Range.Text = myDate.ToShortDateString().ToString();
oBookMark =
"PMAppBkMk";
oDoc.Bookmarks.get_Item(
ref oBookMark).Range.Text = pmApprovTxtBx.Text;
oBookMark =
"PMDateBkMk";
myDate =
Convert.ToDateTime(pmDateTxtBx.Text);
oDoc.Bookmarks.get_Item(
ref oBookMark).Range.Text = myDate.ToShortDateString().ToString();
oBookMark =
"FinakChkBkMk";
//How do I access the checkbox that is stored in the table cell at this bookmark?
// Save as new file with file name of "Incident" + EventNumber + Date.
myDate =
Convert.ToDateTime(eventDateTxtBx.Text);
object saveFileName = @"C:\Plant Tracker\Incident_Report_" + eventNoTxtBx.Text + "_" + myDate.ToShortDateString().ToString().Replace('/', '-');
object AllowSubstitutions = false;
object LineEnding = Word.WdLineEndingType.wdCRLF;
object AddBiDiMarks = false;
MessageBox.Show(saveFileName.ToString());
oDoc.SaveAs(
ref saveFileName, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing,
ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing,
ref AllowSubstitutions, ref LineEnding, ref AddBiDiMarks);
MessageBox.Show("shouldbesaved");


}