【发布时间】:2013-10-28 14:30:27
【问题描述】:
我有一个正在运行的 perl 脚本,它使用 Microsoft Word OLE 并针对我传递给它的内容运行拼写检查。我遇到了一个问题,因为我没有保存文件或文档,所以当我尝试退出 word 时,它希望我保存一些东西(提示另存为)。
我需要能够隐藏此消息或欺骗文档使其认为它已被保存。这是可能的吗?或者您能想到其他解决方案吗?
我尝试了 DisplayAlerts = 0,但似乎也没有帮助。
sub LaunchSpellcheck
{
#Check the version to see if there are updates.
checkVersion();
#Open up MS Word and only display the spellcheck box.
my $Word = Win32::OLE->GetActiveObject('Word.Application') || Win32::OLE->new('Word.Application');
my @windows = FindWindowLike(undef,"Microsoft Word","");
SetActiveWindow(@windows[0]);
$Word->{'Visible'} = 0;
#Add a new document in word
my $TmpDocument = $Word->Documents->Add();
$TmpDocument = $TmpDocument->{Content};
#Add contents of clipboard to document
$TmpDocument ->{Text} = $clipboard->GetText();
#Check the spelling
$Word->ActiveDocument->CheckSpelling;
#Set the content of the file back to the clipboard.
$clipboard->Set($TmpDocument ->{Text});
#Hide save as dialog
$Word->{'DisplayAlerts'} = 0;
$Word->Quit;
MessageBox('The spellchecked content has been saved to your clipboard.','Spellcheck Complete');
#Log that the tool was used to the global log.
TrackUsage();
}
【问题讨论】: