Why the .doc file is locked for editing?  
Author Message
Floored





PostPosted: Wed Mar 08 11:23:20 CST 2006 Top

MS Word VBA >> Why the .doc file is locked for editing?

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.

Word303  
 
 
Cindy





PostPosted: Wed Mar 08 11:23:20 CST 2006 Top

MS Word VBA >> Why the .doc file is locked for editing? 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 :-)

 
 
Andrew





PostPosted: Wed Mar 08 11:55:28 CST 2006 Top

MS Word VBA >> Why the .doc file is locked for editing? I tried. No more Run-time error, but still locking the templateHF.doc and
new.doc files.

This drove me nuts....



> 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?
>

 
 
Word





PostPosted: Mon Mar 13 21:17:14 CST 2006 Top

MS Word VBA >> Why the .doc file is locked for editing?

Save the document first.

Steve Hudson - Word Heretic

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


Andrew reckoned:

>I tried. No more Run-time error, but still locking the templateHF.doc and
>new.doc files.
>
>This drove me nuts....
>

>
>> 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?
>>