How to judge if a Word documnet is opened with automation?

S

Susan Kong

Hi there,

I'm using VC++ to develop Word automation application. Before I opened a
document, I'd like to know if it's already opened in Word so that I know to
activate it or open it.

Any hint?

Thanks.

Susan
 
C

Cindy M -WordMVP-

Hi Susan,
I'm using VC++ to develop Word automation application. Before I opened a
document, I'd like to know if it's already opened in Word so that I know to
activate it or open it.
Well... In the VB world we generally use the Open command (as for
reading/writing to text files, not the Open method in the Word Object model).
If that returns an error (the file can't be opened), then the file is locked.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 
S

Susan Kong

Here are my code:

_Application oWordApp;
if (!oWordApp.CreateDispatch(_T("Word.Application")))
{
AfxMessageBox(_T("CreateDispatch failed."), MB_OK |
MB_SETFOREGROUND);
return;
}

oDocs = oWordApp.GetDocuments();

if (strMyFilePath is already opened in Word) // how to implement this
statement?
oDoc.Activate();
else
}
oDoc.AttachDispatch(oDocs.Open(COleVariant(strMyFilePath),
vFalse, // Confirm Conversion.
vOpt, // ReadOnly.
vOpt, // AddToRecentFiles.
vOpt, // PasswordDocument.
vOpt, // PasswordTemplate.
vOpt, // Revert.
vOpt, // WritePasswordDocument.
vOpt, // WritePasswordTemplate.
vOpt,// Format. // Last argument for Word 97
vOpt, // Encoding // New for Word 2000/2002
vOpt) // Visible
);
oDoc.Activate();
}

I have no idea how to implement this line:
if (strMyFilePath is already opened in Word) // how to implement this
statement?

Thanks a lot.

Susan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top