File in Use problem - again

R

Rhino

I was having this problem a few days ago and posted here. Then, almost
immediately, I solved it. Or thought I had. Now it's back and the steps I
took the last time aren't fixing it this time. I have to believe this is
something fairly fundamental and is caused by simply forgetting almost
everything about the art of writing Word Macros. Here is the original post
again. If anyone can help with this, I'd really appreciate it!!

--

I'm revisiting some VBS scripts that I wrote several years ago to generate
resumes for me (via Word macros) and would like some guidance.
My VBS script is pretty simple:

=======================
' Get arguments into variables
If WScript.Arguments.Count > 0 Then
MsgBox "Too many arguments; expecting none."
WScript.Quit
End If

' Find path for MyDocuments folder
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(&H5&)
strMyDocPath = objFolder.Self.Path

' Start Word Application, open resume.doc in MyDocuments
Set oWd = CreateObject("Word.Application")
oWd.Visible = False
Set oDoc = oWd.Documents.Open(strMyDocPath & "\rhino-resume.doc")

'Run macro named createResumeFromFile, which has no arguments, and catch its
return code
retcde=oWd.Run("createResumeFromFile")

'Save changes to doc on closing and quit Word
oDoc.Save
oDoc.Close
oWd.Quit
Set oWd = Nothing

Set objShell = Nothing

'Exit the script with the value of the return code from the macro/function.
That will be zero from a successful execution or 1 otherwise.
wscript.quit(retcde)
=======================

When I execute this code, I get a message dialog saying:

==============
File In Use

rhino-resume.doc is locked for editing by 'another user'.

Do you want to:
() Open a Read Only copy
() create a local copy and merge your changes later
() Receive notification when the original copy is available

[Ok] [Cancel]
================

Why am I getting this error? I'm pretty sure I don't have any other user
accessing the file. This computer is a standalone machine with internet
access; it is NOT a server. I'm running Windows XP SP2 and have one other
user account on the computer but use it only VERY rarely.

I suspect this problem stems from a message I got several days back where
Word offered something or another - I can't remember the context or message
but it had something to do with saving a copy of the file - but I'm not
sure. Also, I'm not sure what to do about it if I am right. How do I make
Word understand that it can open the file with full read-write access and
run the macro for me?

Since writing the macros and the VBS scripts, I've upgraded from Word 2002
to Word 2007. I'm afraid I've forgotten quite a bit of what I was doing when
I wrote the macros and scripts so I'm not sure if the upgrade is a factor or
not relevant at all....
 
D

Doug Robbins - Word MVP

How about saving rhino-resume as a template (.dot) and then use

Set oDoc = oWd.Documents.Add(strMyDocPath & "\rhino-resume.dot")

in place of

Set oDoc = oWd.Documents.Open(strMyDocPath & "\rhino-resume.doc")

That will create a new docment from the template rather than opening it.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com

Rhino said:
I was having this problem a few days ago and posted here. Then, almost
immediately, I solved it. Or thought I had. Now it's back and the steps I
took the last time aren't fixing it this time. I have to believe this is
something fairly fundamental and is caused by simply forgetting almost
everything about the art of writing Word Macros. Here is the original post
again. If anyone can help with this, I'd really appreciate it!!

--

I'm revisiting some VBS scripts that I wrote several years ago to generate
resumes for me (via Word macros) and would like some guidance.
My VBS script is pretty simple:

=======================
' Get arguments into variables
If WScript.Arguments.Count > 0 Then
MsgBox "Too many arguments; expecting none."
WScript.Quit
End If

' Find path for MyDocuments folder
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(&H5&)
strMyDocPath = objFolder.Self.Path

' Start Word Application, open resume.doc in MyDocuments
Set oWd = CreateObject("Word.Application")
oWd.Visible = False
Set oDoc = oWd.Documents.Open(strMyDocPath & "\rhino-resume.doc")

'Run macro named createResumeFromFile, which has no arguments, and catch
its return code
retcde=oWd.Run("createResumeFromFile")

'Save changes to doc on closing and quit Word
oDoc.Save
oDoc.Close
oWd.Quit
Set oWd = Nothing

Set objShell = Nothing

'Exit the script with the value of the return code from the
macro/function.
That will be zero from a successful execution or 1 otherwise.
wscript.quit(retcde)
=======================

When I execute this code, I get a message dialog saying:

==============
File In Use

rhino-resume.doc is locked for editing by 'another user'.

Do you want to:
() Open a Read Only copy
() create a local copy and merge your changes later
() Receive notification when the original copy is available

[Ok] [Cancel]
================

Why am I getting this error? I'm pretty sure I don't have any other user
accessing the file. This computer is a standalone machine with internet
access; it is NOT a server. I'm running Windows XP SP2 and have one other
user account on the computer but use it only VERY rarely.

I suspect this problem stems from a message I got several days back where
Word offered something or another - I can't remember the context or
message
but it had something to do with saving a copy of the file - but I'm not
sure. Also, I'm not sure what to do about it if I am right. How do I make
Word understand that it can open the file with full read-write access and
run the macro for me?

Since writing the macros and the VBS scripts, I've upgraded from Word 2002
to Word 2007. I'm afraid I've forgotten quite a bit of what I was doing
when
I wrote the macros and scripts so I'm not sure if the upgrade is a factor
or
not relevant at all....
 

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