Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Normal.dot aggravating Message When Closing Word Doc

Status
Not open for further replies.

dbthj

Technical User
Apr 8, 2010
6
US
The standard vbscript suggestion for opening a Word doc (in fact one of the FAQs on this forum suggests this) is something like this:

dim wapp
dim wWord
dim Visible

set wApp = createobject("Word.application")
wApp.visible = true
set wWord = wApp.Documents.Open ("C:\Pathhhhh\Wordfileeeee.doc")

This works just dandy... Unless you already have another Word doc open. If that happens, you get an annoying message when you close the doc, "This file is in use by another application or user.
(C:\Documents and Settings\...\Normal.dot)" and then you have to close a bunch of windows and say no and cancel and such. If you have a suggestion to get around this message, I'd like to hear it. If it is a new line of code. Please show me where in this script it should be placed. If it's been tested, that would be even better. Other suggestions I've encountered elsewhere do not work.
 
This is happening (I think) because an additional instance of Word is being opened instead of a new file within the existing instance. The existing instance still has a file handle open on normal.dot therefore it cannot be accessed by another instance of Word.

Perhaps there is a way to create an object (wApp) from the current instance process ID/handle.

-Geates
 
Perhaps.

This happens if another Word doc is open. It doesn't matter how it got openned. Might have been clicked on, rather than openned in a script.

At any rate, any open Word doc has a handle on Normal.Dot which is some sort of a Microsofty template thingy. You can open as many as you like by clicking on them. No conflict, no harm, no foul. But when you open one from a vbscript (with another open) you get the message problem (upon closing doc). There MUST be a way around this.
 
I found these two scripts with a quick google.

' Open these Word documents..
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
objWord.Documents.Open "C:\Testing\Test1.DOC"
objWord.Documents.Open "C:\Testing\Test2.DOC"
objWord.Documents.Open "C:\Testing\Test3.DOC"


This will open all excel & word documents in the testing directory

strComputer="."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colFileList = objWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_Directory.Name='C:\testing'} Where ResultClass = CIM_DataFile")

Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = TRUE
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
For Each objFile In colFileList
If objFile.Extension = "xls" Or objFile.Extension = "xlsx" Then
objExcel.Workbooks.Open objFile.Name
ElseIf objFile.Extension = "doc" or objFile.Extension = "docx" Then
objWord.Documents.Open objFile.Name
End If
Next



MCITP:EA/SA, MCSE, MCSA, MCDBA, MCTS, MCP+I, MCP
 
you can programatically save and close word documents using the Word.Appliction object. so, you can close them all nicely automatically to get round your issue?
 
GrimR,
This was worth trying. But no cigar, yet. I tried your example, exactly as you wrote it.
' Open these Word documents..
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
objWord.Documents.Open "C:\Testing\Test1.DOC"
objWord.Documents.Open "C:\Testing\Test2.DOC"
objWord.Documents.Open "C:\Testing\Test3.DOC"

What I found is that all 3 documents opened. When closed, they presented no problems....UNLESS there was a Word doc open which had been opened, not using a script, but by clicking on it. In that case, the first two script-opened documents closed without problems. The third, however, caused the Normal.dot problem. (the order in which they were closed does not matter).

There may be some configuration in my laptop which has an impact here. I am fairly certain that my old laptop did not present this problem. Both laptops run (or ran) XP Professional. Current one is SP3. I believe the last one also was SP3. Not sure.

One more test:
I created a second script which opened 3 more documents. Total 6 docs open. All opened using a script. Result: Whenever the last document of the second-script-run was closed, the Normal.dot problem occurred. The first script run (whichever script that was) presented no problems.
 
What about this ?
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
[!]objWord.DisplayAlerts = 0[/!]
...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
And this ?
On Error Resume Next
Set objWord = GetObject(, "Word.Application")
If Err.Number <> 0 Then
Err.Clear
Set objWord = CreateObject("Word.Application")
End If
On Error GoTo 0
objWord.Visible = True
objWord.DisplayAlerts = 0
...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PHV,
I don't follow what all that does, but it is an improvement.
The only drawback is that it opens the documents as minimized. I have to look for them in the taskbar. Do you know how to open them completely?
 
objWord.WindowState = 1 'wdWindowStateMaximize

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
That does it.
Perfect.
Thanks. To assemble the pieces, then, this is the whole script to open 3 Word documents without getting Normal.dot messages.

On Error Resume Next
Set objWord = GetObject(, "Word.Application")
If Err.Number <> 0 Then
Err.Clear
Set objWord = CreateObject("Word.Application")
End If
On Error GoTo 0

objWord.DisplayAlerts = 0
objWord.Visible = True
objWord.WindowState = 1 'wdWindowStateMaximize
objWord.Documents.Open "C:\Testing\Test1.DOC"
objWord.Documents.Open "C:\Testing\Test2.DOC"
objWord.Documents.Open "C:\Testing\Test3.DOC
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top