Recent

Author Topic: How to turn off Word warning messages?  (Read 2987 times)

loaded

  • Hero Member
  • *****
  • Posts: 825
How to turn off Word warning messages?
« on: October 06, 2021, 07:50:21 am »
Hi All,
When I close Excel after creating a new document and adding content in Excel, the process results as I want without any warning.
But when I create a document in Word, add content and then close the document, the "Save Changes" dialog box appears.
It turns out that the ...DisplayAlerts statement works in Excel, but has no effect on Word!!!
What else can be done about the subject?

Sample code snippet;
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.   Excel:olevariant; //add uses comobj
  4. begin
  5.   Excel:=CreateOleObject('Excel.Application');
  6.   Excel.Visible:=True;
  7.   Excel.displayalerts:=false;  // effective
  8.   Excel.Workbooks.Add;
  9.   Excel.ActiveSheet.Cells[1,1]:='Dede';
  10. end;
  11.  
  12. procedure TForm1.Button2Click(Sender: TObject);
  13. var
  14.   Word,Prg:olevariant; //add uses comobj
  15. begin
  16.   Word := CreateOleObject('Word.Application');
  17.   Word.Visible := True;
  18.   Word.DisplayAlerts := false;  //ineffective
  19.   Word.Documents.Add;
  20.   Prg := Word.ActiveDocument.Content.Paragraphs.Add;
  21.   Prg.Range.Text := 'Dede';
  22. end;  

Check out  loaded on Strava
https://www.strava.com/athletes/109391137

noszone

  • New Member
  • *
  • Posts: 46
Re: How to turn off Word warning messages?
« Reply #1 on: October 06, 2021, 10:22:35 am »
Check this out first:
https://stackoverflow.com/questions/47866522/saving-a-word-document-and-setting-displayalerts-to-disable-prompt-to-save
Pay attention to last message in thread.

Then this:
https://forum.lazarus.freepascal.org/index.php/topic,56550.msg420751.html#msg420751
The idea of this to disable review mode, if enabled.

Hope it helps somehow.

loaded

  • Hero Member
  • *****
  • Posts: 825
Re: How to turn off Word warning messages?
« Reply #2 on: October 06, 2021, 10:54:44 am »
Thank you very much for the quick reply noszone, I checked the links, unfortunately there is no solution for now.

Code: Pascal  [Select][+][-]
  1. Private Sub CommandButton1_Click()
  2. Dim oWord As Word.Application
  3. Set oWord = New Word.Application
  4. oWord.Documents.Add
  5. oWord.Options.WarnBeforeSavingPrintingSendingMarkup = False
  6. oWord.Visible = True
  7. If oWord.Options.WarnBeforeSavingPrintingSendingMarkup Then MsgBox "Aktif" Else MsgBox "Pasif"
  8. End Sub

Even the code I run with vba from within word cannot turn off the warnings.  ;D
« Last Edit: October 06, 2021, 11:14:26 am by loaded »
Check out  loaded on Strava
https://www.strava.com/athletes/109391137

noszone

  • New Member
  • *
  • Posts: 46
Re: How to turn off Word warning messages?
« Reply #3 on: October 06, 2021, 11:19:04 am »
Are you sure that used the:
Code: Pascal  [Select][+][-]
  1. Word.ActiveDocument.Save;

loaded

  • Hero Member
  • *****
  • Posts: 825
Re: How to turn off Word warning messages?
« Reply #4 on: October 06, 2021, 11:46:02 am »
For work, I create continuously variable word files, send to printer and that's it, I don't need to save to disk.
If I had to save it to disk there would be no problem.

However, when I use the
Code: Pascal  [Select][+][-]
  1. oWord.ActiveDocument.Save
code, the save dialog box appears.
Check out  loaded on Strava
https://www.strava.com/athletes/109391137

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: How to turn off Word warning messages?
« Reply #5 on: October 06, 2021, 11:50:36 am »
Yes. Tested. But that is a Microsoft issue and does not belong on THIS forum.
Ask Microsoft.
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

Zvoni

  • Hero Member
  • *****
  • Posts: 2327
Re: How to turn off Word warning messages?
« Reply #6 on: October 06, 2021, 12:11:50 pm »
RTFM
https://docs.microsoft.com/en-us/office/vba/api/word.document.save
Quote
Remarks

If a document has not been saved before, the Save As dialog box prompts the user for a file name.
If you just want to close Word without saveing, use Quit
https://docs.microsoft.com/en-us/office/vba/api/word.application.quit(method)
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: How to turn off Word warning messages?
« Reply #7 on: October 06, 2021, 12:20:48 pm »
How I read this is simply allow the save but do not show the dialog.
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

ccrause

  • Hero Member
  • *****
  • Posts: 856
Re: How to turn off Word warning messages?
« Reply #8 on: October 06, 2021, 12:23:24 pm »
The document.close method takes optional parameters, the first of which is called SaveChanges, which you can set to wdDoNotSaveChanges.

Zvoni

  • Hero Member
  • *****
  • Posts: 2327
Re: How to turn off Word warning messages?
« Reply #9 on: October 06, 2021, 12:36:42 pm »
How I read this is simply allow the save but do not show the dialog.
Not quite.
The only way to escape the SaveAs-Dialog for an unsaved and untitled document is to check if it has been already saved once, and then to provide the filename in a (separate) SaveAs2-Call
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

Zvoni

  • Hero Member
  • *****
  • Posts: 2327
Re: How to turn off Word warning messages?
« Reply #10 on: October 06, 2021, 12:37:11 pm »
The document.close method takes optional parameters, the first of which is called SaveChanges, which you can set to wdDoNotSaveChanges.
This doesn't close the Word-Application, just the document
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

loaded

  • Hero Member
  • *****
  • Posts: 825
Re: How to turn off Word warning messages?
« Reply #11 on: October 06, 2021, 12:55:12 pm »
Thaddy,Zvoni and ccrause thank you very much for the reply.
I had a similar problem with Lazarus and VB6 before. Naturally, when the problem occurred, I initially thought there was a problem with the component object model.
But when I went deeper, I saw that WORD was about itself.
Yes. Tested. But that is a Microsoft issue and does not belong on THIS forum. Ask Microsoft.
You're right Thaddy, the problem is windows, but if you don't mind, let's not delete the message, maybe it will make someone like me wake up early to such an error.
« Last Edit: October 06, 2021, 01:15:17 pm by loaded »
Check out  loaded on Strava
https://www.strava.com/athletes/109391137

 

TinyPortal © 2005-2018