2013-10-28 27 views
2

我有一個perl腳本,我使用的是Microsoft Word OLE,並運行拼寫檢查對我傳給它的conent。我遇到了一個問題,因爲我不保存文件或文檔,所以當我嘗試並退出單詞時,它希望我保存某些內容(另存爲)。使用Word OLE的Perl Supress Saveas對話框

我需要能夠抑制此消息或誘使文檔認爲它已保存。這是可能的還是你可以想到另一種解決方案?

我試過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(); 
} 

回答

0

這個工作對我來說:

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