Var
MSWord : Variant
procedure TTMDtlForm.ExecuteTheMacro;
var
WHandle : HWnd;
begin
try
// If file selected
If OpenDialog1.execute Then
begin
// Set Flag to False
FoundWord:=False;
try
// If word is already running, obtain a link and set flag to true
MsWord := GetActiveOleObject('Word.Basic');
FoundWord := True;
except
try
// Start new instance of word and set flag to True
MsWord := CreateOleObject('Word.Basic');
FoundWord := True;
except
// Display error message
ShowMessage('Could not start word');
end;
end;
// If Link established
if FoundWord then
begin
try
MsWord.AppShow;
MsWord.ScreenUpdating(0);
MSWord.FileOpen(OpenDialog1.FileName);
MsWord.ScreenUpdating(1);
MsWord.ScreenRefresh;
// Maximize and bring Word to front
WHandle := FindWindow('OpusApp',Nil);
if isWindow(WHandle) then
ShowWindow(WHandle,SW_SHOWMAXIMIZED);
except
MessageDlg('TF - Error in Word Basic',mtError,[mbOK],0);
MsWord.ScreenUpdating(1);
end;
end;
end;
finally
end;
end;