Open Word file with Excel VBA

K

KP

Hi,

I want to open a Word file using an Excel macro, but it doesn't work as I
want.
I get the message: This file is locked for editing by another user....."
It must have something to do with the macro, because the file is not locked
or already open.
How can I avoid this message?

Dim wdApp As Object
Dim wdDoc As Object
Set wdApp = CreateObject("Word.application")
wdApp.Visible = True
Set wdDoc = wdApp.Documents.Open _
(Filename:="C:\Documents and Settings\XXX\Desktop\test.doc")

Regards
Kaj Pedersen
 
J

Javed

The code worked for me.I think you have opened the file
programmatically earlier and not closed.It will not be visible.
Try to close the file containg macro .reopen the file and try once.
 
W

Walter Briscoe

In message <[email protected]
s.com> of Sun, 25 Sep 2011 22:50:12 in microsoft.public.excel.programmin
g said:
The code worked for me.I think you have opened the file
programmatically earlier and not closed.It will not be visible.
Try to close the file containg macro .reopen the file and try once.

I roughly agree. The OP might reboot the system to start with a known
position and see if the problem disappears.

There seems to be a lack of facilities in Office to tidy up
automatically after Office opens another application.
One can easily get orphan applications which are hidden.
e.g. With code (untested) like:
CreateObject("Word.application").Documents.Open(Filename:=foo)

I expect there is a hidden instance of Word locking "C:\Documents and
Settings\XXX\Desktop\test.doc". On my Vista system running Office 2003,
I would open the Task Manager, after right-clicking on an empty part of
the Taskbar, and looking for WINWORD.EXE in the processes tab. "End
Process" with confirmation should zap the problem.

The OP does not say which version of Office or operating system shows
the problem.
 

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