Link to home
Start Free TrialLog in
Avatar of Programm
Programm

asked on

Getting error when I am replacing text in word 2013 document.

When my program is replacing text in word documents, using Delphi XE7 It get this error, „This command is not available“  It only happens with few users. Some users can do it with no errors.
Users have all Windows 7 and office 2013.

First we open the document.
procedure TfrmAttachmentsDOA.OpenWord;
begin
  if VarIsClear(FApp) then
    FApp := CreateOleObject('Word.Application');
    FApp.Visible := false;
  FDoc := FApp.Documents.Open( FSkraarheiti );
end;

Open in new window

Then we replace the text we get the error „This command is not available“
The question is way is the document read only at this time?
procedure FindReplaceAll(strFinna, strReplace: OleVariant; OleObj: Variant);
var
   strResponse: string;
   wdFindContinue, wdReplaceAll: integer;
   count : integer;
begin
   count := 0;
   wdFindContinue  := 1;
   wdReplaceAll    := 2;

   while ( length(strReplace)  > 0 ) or ( count = 0 ) do
   begin
      count := count + 1;
      if length(strReplace) > 251 then
      begin
         strResponse := AnsiMidStr ( strReplace, 1, 220) + strFinna;
         strReplace := AnsiMidStr( strReplace, 221, length(strReplace));
      end
      else
      begin
         strResponse := strReplace;
         strReplace := '';
      end;

      OleObj.application.Selection.Find.ClearFormatting;
      OleObj.application.Selection.Find.Text := strFinna;
      OleObj.application.Selection.Find.MatchCase := False;
      OleObj.application.Selection.Find.MatchWholeWord := False;
      OleObj.application.Selection.Find.MatchWildcards := False;
      OleObj.application.Selection.Find.MatchSoundsLike := False;
      OleObj.application.Selection.Find.MatchAllWordForms := False;
      OleObj.application.Selection.Find.Forward := True;
      OleObj.application.Selection.Find.Wrap := wdFindContinue;
      OleObj.application.Selection.Find.Format := True;
      OleObj.application.Selection.Find.Replacement.ClearFormatting;
      OleObj.application.Selection.Find.Replacement.Text := strResponse;
     //Here we get the error.
      OleObj.application.Selection.Find.Execute(Replace := wdReplaceAll);
   end;
end;

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.