Integrating Delphi to Word (enabling Save Word button)

Asked

Viewed 373 times

5

Some time ago I created a system that integrates the MS Word with the Delphi, only that the button of Save Word gets disabled.

botão de Salvar desabilitado

It would be important that this button was enabled, because it is already saved in the place where the file was created. I’ll put the code of how I open the document.

procedure TfrmConsultas.btnCaregarClick(Sender: TObject);
var
  OleContainer: TOleContainer;
begin
  try
    with OleContainer do
    begin
      if OleObjectInterface <> Nil then
      begin
        DestroyObject;
      end;
      //Nome do arquivo usado para abrir o arquivo de entrvista de Consulta
      vNomeArquivo  := 'Nome do Arquivo';
      // Cria o Arquivo a partir do conteúdo de um arquivo de modelo.
      try
        // Código que deve ser tratado caso haja uma exceção
        OleContainer.CreateObjectFromFile(vNomeArquivo, False);
        OleContainer.DoVerb(ovPrimary);
        OleContainer.DoVerb(ovShow);
        OleContainer.DoVerb(ovUIActivate);
        OleContainer.DoVerb(ovInPlaceActivate);
        Perform(WM_LBUTTONDBLCLK, MK_LBUTTON, 0);

        if (DM.tbConsultas.State in [dsInsert]) or
           ((DM.tbConsultasMODELO_ARQUIVO.AsString <> '') and
            (cbbModelos.Text <> '')) or ((cbbModelos.Text <> '') and
            (DM.tbConsultasMODELO_ARQUIVO.AsString = '')) then
          FindAndReplace;
      except
        //  Fechar o arquivo
        DestroyObject;
      end;
    end;
  finally
    Screen.Cursor := crDefault;
  end;

end;

After modifying the content I saved.

OleContainer.OleObject.SaveAs (FileName, wdFormatDocument, EmptyParam, EmptyParam, False);
  • I want to know if you can activate this button
  • 1

    Already tried to check if you can there in toolbar customization?

  • You can save it with the command WordDocument1.SaveAs(docdestino); put on the exit button so the user already leaves saving.

  • tried on startup of the program already direct this button as enabled? I don’t know your system anymore in Form.create put all the properties you want in the standard form enabled or not. I think it’s just that a successful hug.

  • @user113557 the button of the image that is in question was not created by me it is word I have no way to enable you by putting botao.doWord.enable := True if you notice the image it is from the system.

  • there is a TOleContainer that I bring the word screen.

1 answer

1

Normally, the save button is only enabled after some change in the document is performed by Word itself (without Automation). To make Word understand that the document can be saved, use the Saved property, as in the example:

var Word, Doc: OleVariant; begin Word := CreateOleObject('Word.Application'); Doc := Word.Documents.Add; ... //outros comandos Doc.Saved := False; end;

  • Oops! I will test only that I can not test now much, thank you!

  • Can’t make it work!

  • 1

    Put the relevant parts of your code so we can try to understand what’s missing.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.