Home: Perl Programming Help: Beginner:
MS Word OLE Supress Save As Dialog



sbbcarl
New User

Oct 28, 2013, 7:38 AM


Views: 722
MS Word OLE Supress Save As Dialog

I have a perl script that I am running which uses Microsoft Word OLE and runs spellcheck against the conent I pass to it. I am running into a problem as I am not saving a file or document so when i try and quit word, it wants me to save something (Prompt Save As).I need to be able to supress this message or trick the document into thinking it was already saved. Is this possible or can you think of another solution?

I tried DisplayAlerts = 0 and that didnt seem to help either.

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