RhinoCan
Programmer
- Oct 30, 2011
- 4
I am having an intermittent problem with a couple of my VBScripts. Sometimes, when I execute them, a dialog window pops up that tells me the following:
==========
File In Use
foo.doc is locked for editing by [me].
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]
===========
I don't understand why I am getting this though. I don't consciously access that file except when I run the VBScripts.
I am not very fluent with VBScript so I may be doing something foolish with it; perhaps I need to specify an option to release the file as I finish with it or something like that? Then again, this problem IS intermittent so that's probably not it, otherwise I'd get it all the time.
I'd like to know what I need to do to avoid this issue in the future. For what it's worth, I have resolved the problem by rebooting the computer but I certainly don't want to do that routinely; I'd rather prevent the problem in the first place.
Here are the VBScripts in question:
===========
[CreateWordMacros.vbs]
' 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 & "\foo.doc")
' Temporary - Determine value of document path. (c:\Documents and Settings\Sparky\My Documents)
' MsgBox "The document originates at this directory: " & strMyDocPath & "."
'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)
===========
===========
[ExportWordMacros.vbs]
' Get arguments into variables
If WScript.Arguments.Count < 1 Then
MsgBox "Too few arguments; expecting one."
WScript.Quit
Elseif WScript.Arguments.Count > 1 then
MsgBox "Too many arguments; expecting one."
WScript.Quit
Else
strArg1 = WScript.Arguments.Item(0)
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 & "\foo.doc")
'Run macro named exportMacros, which has one argument
retcde = oWd.Run("exportMacros",strArg1)
'Save changes to doc on closing and quit Word
oDoc.Save
oDoc.Close
oWd.Quit
Set oWd = Nothing
Set objShell = Nothing
WScript.quit(retcde)
===========
==========
File In Use
foo.doc is locked for editing by [me].
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]
===========
I don't understand why I am getting this though. I don't consciously access that file except when I run the VBScripts.
I am not very fluent with VBScript so I may be doing something foolish with it; perhaps I need to specify an option to release the file as I finish with it or something like that? Then again, this problem IS intermittent so that's probably not it, otherwise I'd get it all the time.
I'd like to know what I need to do to avoid this issue in the future. For what it's worth, I have resolved the problem by rebooting the computer but I certainly don't want to do that routinely; I'd rather prevent the problem in the first place.
Here are the VBScripts in question:
===========
[CreateWordMacros.vbs]
' 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 & "\foo.doc")
' Temporary - Determine value of document path. (c:\Documents and Settings\Sparky\My Documents)
' MsgBox "The document originates at this directory: " & strMyDocPath & "."
'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)
===========
===========
[ExportWordMacros.vbs]
' Get arguments into variables
If WScript.Arguments.Count < 1 Then
MsgBox "Too few arguments; expecting one."
WScript.Quit
Elseif WScript.Arguments.Count > 1 then
MsgBox "Too many arguments; expecting one."
WScript.Quit
Else
strArg1 = WScript.Arguments.Item(0)
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 & "\foo.doc")
'Run macro named exportMacros, which has one argument
retcde = oWd.Run("exportMacros",strArg1)
'Save changes to doc on closing and quit Word
oDoc.Save
oDoc.Close
oWd.Quit
Set oWd = Nothing
Set objShell = Nothing
WScript.quit(retcde)
===========