使用Word OLE的Perl Supress Saveas对话框

时间:2013-10-28 14:30:28

标签: perl dialog ole

我有一个运行的perl脚本,它使用Microsoft Word OLE并对我传递给它的conent运行拼写检查。我遇到了一个问题,因为我没有保存文件或文档所以当我尝试退出单词时,它希望我保存一些东西(提示另存为)。

我需要能够抑制此消息或欺骗文档,使其认为已经保存。这是可能的,还是你能想到另一个解决方案?

我尝试过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();
}

1 个答案:

答案 0 :(得分:0)

这对我有用:

my $Word = Win32::OLE->GetActiveObject('Word.Application') || Win32::OLE->new('Word.Application');
$Word->{'DisplayAlerts'} = 0;
....