PDA

View Full Version : How to wait till the save operation is completed?



edwinyeah
12-21-2009, 04:33 AM
Hi,

First, thanks for this forum and everyone who as contributed to this community :)

I have a problem with calling Document.SaveAs method with large documents, it seems that the save operation of a Word document is asynchronous, ie. after calling SaveAs it returns immediately but with large documents the actual save operation may not has been finished and it's in progress in another thread, this will lead to problems in some cases.

So I wonder if there is a property that indicates the *actual* save operation is in progress or finished? Or other ways else?


PS. I use Delphi to call the automation interface of Word, if it means something in discussing this problem, but I don't' think so?

Thank you in advance.

Tinbendr
12-21-2009, 09:36 AM
Perhaps

DoEvents
Do
Loop Until ActiveDocument.Saved

Of course, if the document is not the active one, you'll have to refer to it by object.


Dim MyDoc as Document
Set MyDoc = Documents.Add 'One example

'Do other things here.

MyDoc.SaveAs "MyFilename.doc"

DoEvents
Do
Loop Until MyDoc.Saved

fumei
12-21-2009, 03:06 PM
Do Events is most likely what you need to..ummm...Do.

edwinyeah
12-22-2009, 12:10 AM
Hi Tinbendr,

Thank you for the code sample, but the Saved become true once the SaveAs method is called...

edwinyeah
12-22-2009, 04:18 AM
Hi all,

It seems that the problem I have is to related to the SaveAs method or the Saved property ,but after calling Range.InsertFile(aFileName), aFileName will be unlocked and you don't know when will it be unlocked...

fumei
12-22-2009, 10:14 AM
You never mentioned anything about using a Range.InsertFile.

It is helpful to give full information.

edwinyeah
12-22-2009, 11:11 PM
Hi Fumei.

Sorry my the confusion, it's my fault. Now it turned out that it's totally unrelated to SaveAs and Saved, it's all about the file that's called by Range.InsertFile will be locked and you have no control and don't know when it will be unlocked.

My workaround. When a file is called by Range.InsertFile, don't write data to it anymore.

Thank you all for you help.

fumei
12-23-2009, 12:52 PM
OK, but I remain confused myself.

"My workaround. When a file is called by Range.InsertFile, don't write data to it anymore."

How can you write data to it? .InsertFile does not write data to the inserted file. It simply inserts the contents into the range (of the current document one assumes). If the InsertFile file is "locked" - for opening, or for forms? - it depends on what you mean by "locked".

If the InsertFile file is protected for forms, then it is inserted, and the protection is stripped. If it is protected for opening, then a dialog requesting the passsword is displayed.

But - shrug - whatever. Something seems to have worked out for you.