Word 2007 : “Saving the autorecovery file is postponed”.

Add-in Express™ Support Service
That's what is more important than anything else

Word 2007 : “Saving the autorecovery file is postponed”.
I try to save locally onDocumentBeforeSave event, then I always get a message window ... 
Andrei Smolin


Add-in Express team


Posts: 14677
Joined: 2006-05-11
Hello Tamas,

Then this is AutoSave after all... I got an impression that this occurs whenever you save the document. Whence my code.

Here's what I suggested to do to find out if Word is autosaving:

Andrei Smolin writes:
I'd recommend checking if the event was generated by the user action first. To do this, you can intercept all Ribbon controls which generate this event or result in generating it and set a flag in the event handlers; if the flag is not set in BeforeDocumentSave, then the event is caused by Word itself and you don't need to cancel it.


Oh, I've recalled a simper way, see Macros in Office Word 2007 cannot differentiate between "Auto Recovery Save" and "Manual Save" in the DocumentBeforeSave event

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 25 Jul, 2013 01:52:09 Top
Tamas Szabo




Posts: 16
Joined: 2008-07-03
Hello Andrei,

Sorry, I was wrong.
The parameter "SaveAsUI" is only TRUE,
when "Save" action is generated first by the user
or "Save as" action is generated by the user.
The second "Save" or the "Auto Recovery Save" set the parameter "SaveAsUI" to False;

I've checked the MS website and I've tried the code there
and I got the following error:

" Error:Method 'IsAutosaveEvent' not supported by automation object"

the sourcecode:

wDBasic : olevariant;
...
try
wDBasic := WordApp.WordBasic;
if wDBasic.IsAutosaveEvent then begin
CnDebugger.LogMsg(' adxWordAppEvents1DocumentBeforeSave IsAutosaveEvent');
end
else begin
CnDebugger.LogMsg(' adxWordAppEvents1DocumentBeforeSave IsAutosaveEvent');
end;
except
on E:Sysutils.Exception do begin
CnDebugger.LogMsg(' adxWordAppEvents1DocumentBeforeSave Error:'+ E.message);
end;
end;

My problem is the following:
If I know that there is "Auto Recovery Save" I still have to save the Document
into the database and I have to set Cancel to TRUE in the onDocumentBeforeSave event.
After the event I get the following message: "Saving the autorecovery file is postponed."
Can I disable this message somehow? It doesn't help if I set word displayalerts to wdAlertsNone.

Best Regards
Tamas
Posted 31 Jul, 2013 11:14:17 Top
Andrei Smolin


Add-in Express team


Posts: 14677
Joined: 2006-05-11
Hello Tamas,

As explained the problem occurs because you cancel the DocumentBeforeSave event when Word saves the AutoRecovery file. That is, to overcome the issue you need to filter out the DocumentBeforeSave events initiated by Word, not by the user.

One of the apporaches is given below:

Andrei Smolin writes:
I'd recommend checking if the event was generated by the user action first. To do this, you can intercept all Ribbon controls which generate this event or result in generating it and set a flag in the event handlers; if the flag is not set in BeforeDocumentSave, then the event is caused by Word itself and you don't need to cancel it.


As to the other (simpler approach), it works for me in Word 2007 SP3.

procedure TAddInModule.adxWordAppEvents1DocumentBeforeSave(
  ASender: TObject; const Doc: _Document; var SaveAsUI, Cancel: WordBool);
var
  wDBasic : olevariant;
begin
  try
    wDBasic := WordApp.WordBasic;
    if wDBasic.IsAutosaveEvent then begin
      OutputDebugString('!!! IsAutosaveEvent');
    end
    else begin
      OutputDebugString('!!! NOT IsAutosaveEvent');
    end;
  except
    on E:Sysutils.Exception do begin
      OutputDebugString(PAnsiChar('!!! Error:'+ E.message));
    end;
  end;
end;


Tamas Szabo writes:
If I know that there is "Auto Recovery Save" I still have to save the Document
into the database and I have to set Cancel to TRUE in the onDocumentBeforeSave event.


Sorry? Are you saying that you need to cancel DocumentBeforeSave even if it is the AutoRecovery save? If so, getting the error message cannot be avoided.

Tamas Szabo writes:
After the event I get the following message: "Saving the autorecovery file is postponed."


The code above doesn't produce that message.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 01 Aug, 2013 03:26:49 Top
Tamas Szabo




Posts: 16
Joined: 2008-07-03
Hello Andrei,

I want to be clear about my aim.
I need to trap the onDocumentBeforeSave event,
because in specific cases I need to save the document in a special way .
This works fine most of the time, but not when an Autorecovery Save is triggered.
The document that is passed to DocumentBeforeSave is the current document,
my functions run ok, but then after the Event,
I get the following message:"Saving the autorecovery file is postponed." .
When a user normally presses on Save,this does not happen and all is fine,
so my function should not be the problem.
This problem appears only in case of Word 2007.

This is a code example to test the problem. The "...postponed." message appears.
/w2007 sp3/

...
var
wOutFileName: OLEVariant;
wDBasic : OLEVariant;
begin
CnDebugger.LogMsg('!!! adxWordAppEvents1DocumentBeforeSave');
wOutFileName := 'C:\aFileName';
CnDebugger.LogMsg('!!! before SaveAs');
try
wDBasic := WordApp.WordBasic;
if wDBasic.IsAutosaveEvent then begin
CnDebugger.LogMsg(' adxWordAppEvents1DocumentBeforeSave IsAutosaveEvent');
end
else begin
CnDebugger.LogMsg(' adxWordAppEvents1DocumentBeforeSave IsAutosaveEvent');
end;
except
on E:Sysutils.Exception do begin
CnDebugger.LogMsg(' adxWordAppEvents1DocumentBeforeSave Error:'+ E.message);
end;
end;
Doc.SaveAs(wOutFileName, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam,
EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam);
Cancel := True; //or False
CnDebugger.LogMsg('!!! adxWordAppEvents1DocumentBeforeSave exit');
end;

I received the same error message when Cancel set to False.

Do you have any idea or suggestion how to solve the saving of documents in a different way
to avoid this message?

Best Regards
Tamas
Posted 02 Aug, 2013 07:42:42 Top
Andrei Smolin


Add-in Express team


Posts: 14677
Joined: 2006-05-11
Tamas,

I would let Word do its stuff when the DocumentBeforeSave event is triggered by Word itself. Do you get this message if you comment out the SaveAs call?

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 05 Aug, 2013 02:29:46 Top
Tamas Szabo




Posts: 16
Joined: 2008-07-03
Hello Andrei,

I'm sorry for the late answer, I was on my well deserved holiday :-)

Switching off the Autorecovery temporarily solved the problem,
but we should find a better solution.

When I comment out the SaveAs call and Cancel set to True I receive the warning.
When I comment out the SaveAs call and Cancel is False there is no warning.
When Cancel is False and I call the Saveas then the warning message appears.
We should find a solution for the situation when Cancel is True and I call the SaveAs and there is
no waring messages as it works in Office 2010.

Best Regards
Tamas
Posted 27 Aug, 2013 04:34:11 Top
Andrei Smolin


Add-in Express team


Posts: 14677
Joined: 2006-05-11
Hello Tamas,

Tamas Szabo writes:
I need to trap the onDocumentBeforeSave event,
because in specific cases I need to save the document in a special way .
This works fine most of the time, but not when an Autorecovery Save is triggered.
...
I get the following message:"Saving the autorecovery file is postponed." .


Tamas Szabo writes:
If I know that there is "Auto Recovery Save" I still have to save the Document
into the database and I have to set Cancel to TRUE in the onDocumentBeforeSave event.


Could you please confirm that you need to perform a custom save in the DocumentBeforeSave event which is generated by AutoRecovery?

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 27 Aug, 2013 05:33:32 Top
Tamas Szabo




Posts: 16
Joined: 2008-07-03
Hello Andrei,

Yes, I need to save all versions of documents into database at once.
Doesn't matter if the event was initiated by the user or the autorecovery.
As I mentioned earlier it works in office2010 as expected but in office2007 there
is that annoying warning message.


Best Regards
Tamas
Posted 27 Aug, 2013 09:54:01 Top
Andrei Smolin


Add-in Express team


Posts: 14677
Joined: 2006-05-11
Hello Tamas,

From what I know, there's no way to bypass the warning in this scenario.

Your last chance is Cindy Meister, the Word guru. You can find her on the Word for Developers forum, see http://social.msdn.microsoft.com/Forums/en-US/home?forum=worddev.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 27 Aug, 2013 10:06:03 Top
Tamas Szabo




Posts: 16
Joined: 2008-07-03
Hello Andrei,

Thank you for your answer that is what I was afraid of. :-)

But, what do you think about the following idea:

We would check the status of the Autorecovery.
If it is set then we would give the value to a TTimer,
and switch off the Autorecovery. Then the TTimer would initiate
my custom save event.
Before quit from word we should set the original value to Autorecovery.
Does it make any sense?

Best Regards
Tamas
Posted 27 Aug, 2013 10:19:19 Top