3

I am writing some very simple code to open a word document, save it in a new format and close document. However I run into problems if the document has been left in a locked state and get the 'File in Use' dialog.

File in Use Dialog

Now I would be delighted to pick option 1 or 3 automatically, but can't seem to find a way. Ideally I would prevent it from showing at all via a parameter on the open method. I'm using Delphi, but that's not really relevant.

    Wordapp.documents.Open(InputFile);
Deduplicator
  • 44,692
  • 7
  • 66
  • 118
Toby Allen
  • 10,997
  • 11
  • 73
  • 124

1 Answers1

12

Calling open with ReadOnly set to true seems to fix this issue.

    Readonly := true;
    Wordapp.documents.Open(FName, false, Readonly);  //3rd parameter is readonly

Reference: http://msdn.microsoft.com/en-us/library/office/ff835182.aspx

Toby Allen
  • 10,997
  • 11
  • 73
  • 124
  • Just what I was looking for thanks. appWord.Documents.Open("c:\test\WK14.doc", False, True, , , , , , , , , False) The false at the end stops it being visible as well if anyone wants that function. – perfo Apr 09 '18 at 00:26