bcb操作word问题,请进(100分哦)
下面这段是用WordApplication控件操作word的,现在的问题是第一次运行打开word成功后关闭word,再点击运行这段,就会在下面的地方出问题,有说明
try
{
try
{
WordApplication->Connect();
}
catch(Exception &exception)
{
MessageDlg("Word可能没有安装或安装不正确!", mtError,
TMsgDlgButtons() << mbYes, 0);
Abort;
}
WordApplication->GetDefaultInterface()->Visible = True;
WordApplication->set_Caption(StringToOleStr("结果"));
WordApplication->Documents->Add(Template, NewTemplate);////到这出错,大概意思就是docunment指针有问题,但是不关闭word连续运行打开几个文档都没问题。
//Assign WordDocument component
WordDocument->ConnectTo(WordApplication->Documents->Item(ItemIndex));
//Turn Spell checking off because it takes a long time if enabled and slows down Winword
WordApplication->Options->CheckSpellingAsYouType = False;
WordApplication->Options->CheckGrammarAsYouType = False;
//Insert data
WordDocument->Sentences->Last->Paste();
}
catch(Exception &exception)
{
Application->ShowException(&exception);
WordApplication->Disconnect();
}