Why the .doc file is locked for editing?

A

Andrew

Hi, friends,

When running the following code, I got an error at line msdoc.Close (see
code below)

Run-time error -2147417851(80010105)

Dim mswd As New Word.Application
Dim msdoc As Word.Document

Set msdoc = mswd.Documents.Open("c:\templateHF.doc")
msdoc.Range.InsertFile "c:\CQInfo.doc"

msdoc.Close
mswd.Quit

As a result, could not open file TemplateHF.doc anymore. It said this file is
locked for editing.

(If before msdoc.Close, I add: msdoc.SaveAs "c:\new.doc", this new.doc is
locked for edition too).

Any ideas? Thanks.
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?QW5kcmV3?=,

Does it help at all if you
Set msdoc = Nothing
Set mswd = Nothing

in order to release these object pointers?
When running the following code, I got an error at line msdoc.Close (see
code below)

Run-time error -2147417851(80010105)

Dim mswd As New Word.Application
Dim msdoc As Word.Document

Set msdoc = mswd.Documents.Open("c:\templateHF.doc")
msdoc.Range.InsertFile "c:\CQInfo.doc"

msdoc.Close
mswd.Quit

As a result, could not open file TemplateHF.doc anymore. It said this file is
locked for editing.

(If before msdoc.Close, I add: msdoc.SaveAs "c:\new.doc", this new.doc is
locked for edition too).

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 :)
 
A

Andrew

I tried. No more Run-time error, but still locking the templateHF.doc and
new.doc files.

This drove me nuts....
 
W

Word Heretic

G'day Andrew <[email protected]>,

Save the document first.

Steve Hudson - Word Heretic

steve from wordheretic.com (Email replies require payment)
Without prejudice


Andrew reckoned:
 

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