J
Jeffery B Paarsa
Hello,
I start Word by double clicking on a Word template of .dot “Assuming Winword
is not listed in my task manager window either on the Applications tab or
Processes tab†before I do this double clicking. AutoNew macro will kick off
by hiding the Application and displaying the Userform and following code will
be executed:
Private Sub CMDPrint_Click()
‘ some codes for editing etc….
NPPkg.Hide
WordBasic.DisableAutoMacros 1
Call openHippa(NPPkg.PFName.Text, NPPkg.PLName.Text)
Call openMedHistory(NPPkg.PFName.Text, NPPkg.PLName.Text,
NPPkg.PVDate.Text)
Call openRegInfo(NPPkg.PFName.Text, NPPkg.PLName.Text, NPPkg.PVDate.Text)
Call openProgNote(NPPkg.PFName.Text, NPPkg.PLName.Text, NPPkg.PVDate.Text)
If NPPkg.ProbList.Value = True Then
Call openProbList(NPPkg.PFName.Text, NPPkg.PLName.Text,
NPPkg.PVDate.Text)
End If
WordBasic.DisableAutoMacros 0
.Protect wdAllowOnlyFormFields, Noreset:=True
.Close wdDoNotSaveChanges
End With
End Sub
Sub openHippa(ByRef PFName As String, ByRef PLName As String)
Dim HippaForm As Document
' WordBasic.DisableAutoMacros 1
Set HippaForm = Word.Documents.Add(Template:=FileSystem.CurDir +
"\(MR)Hippa Form.dot", Visible:=False)
With HippaForm
.Unprotect
Call UpdHeadFoot
.Bookmarks("PFName").Range _
.InsertBefore PFName
.Bookmarks("PFName").Range.Font.Color = wdColorRed
.Bookmarks("PLName").Range _
.InsertBefore PLName
.Bookmarks("PLName").Range.Font.Color = wdColorRed
ActiveDocument.Fields.Update
.Protect wdAllowOnlyFormFields, Noreset:=True
.PrintOut
.Close wdDoNotSaveChanges
End With
End Sub
All the other subroutines of openMedHistory, openRegInfo, openProgNote and
openProbList are almost identical to openHippa code that you will see above,
except UpdHeadFoot which is for updating Header/Footer section for each
document. While I am watching the directory I can see that all the temporary
~$R)….files will be created and after a few second will be eliminated after
the printout was spooled for the printer. For the first round I have no
problem and all my 4-5 documents will be printed with no problem. But after
eliminating the temporary ~$R)… files and spooling the printouts I don’t see
the Winword on the Task manager Applications window tab but I still can see
the WinWord running on the Task manager Processes tab. Now if I do the same
act of double clicking on the same Word template .dot I will get the
following dialog error:
Run-time error ‘5151’;
Word was unable to read this document. It may be corrupt.
Try one or more of the following:
*Open and Repair the file.
*Open the file with the Text Recovery converter.
Now if I terminate the Process tree for the WinWord thru the task manager
then I would be able to run and print my documents one more time without any
error dialog but the second time I have the same problem. Basically between
each print I have to terminate the WinWord thru the task manager to be able
to get the next round of printing! Looking at the directory of my word
templates on the “Date Modified†field I don’t see any changes/corruption
that may have been applied to my Word templates, so accidental corruption is
out of picture.
Question: Why won’t WinWord does not terminate even though I explicitly
close the documents? How can I force this termination thru the VBA macro
I start Word by double clicking on a Word template of .dot “Assuming Winword
is not listed in my task manager window either on the Applications tab or
Processes tab†before I do this double clicking. AutoNew macro will kick off
by hiding the Application and displaying the Userform and following code will
be executed:
Private Sub CMDPrint_Click()
‘ some codes for editing etc….
NPPkg.Hide
WordBasic.DisableAutoMacros 1
Call openHippa(NPPkg.PFName.Text, NPPkg.PLName.Text)
Call openMedHistory(NPPkg.PFName.Text, NPPkg.PLName.Text,
NPPkg.PVDate.Text)
Call openRegInfo(NPPkg.PFName.Text, NPPkg.PLName.Text, NPPkg.PVDate.Text)
Call openProgNote(NPPkg.PFName.Text, NPPkg.PLName.Text, NPPkg.PVDate.Text)
If NPPkg.ProbList.Value = True Then
Call openProbList(NPPkg.PFName.Text, NPPkg.PLName.Text,
NPPkg.PVDate.Text)
End If
WordBasic.DisableAutoMacros 0
.Protect wdAllowOnlyFormFields, Noreset:=True
.Close wdDoNotSaveChanges
End With
End Sub
Sub openHippa(ByRef PFName As String, ByRef PLName As String)
Dim HippaForm As Document
' WordBasic.DisableAutoMacros 1
Set HippaForm = Word.Documents.Add(Template:=FileSystem.CurDir +
"\(MR)Hippa Form.dot", Visible:=False)
With HippaForm
.Unprotect
Call UpdHeadFoot
.Bookmarks("PFName").Range _
.InsertBefore PFName
.Bookmarks("PFName").Range.Font.Color = wdColorRed
.Bookmarks("PLName").Range _
.InsertBefore PLName
.Bookmarks("PLName").Range.Font.Color = wdColorRed
ActiveDocument.Fields.Update
.Protect wdAllowOnlyFormFields, Noreset:=True
.PrintOut
.Close wdDoNotSaveChanges
End With
End Sub
All the other subroutines of openMedHistory, openRegInfo, openProgNote and
openProbList are almost identical to openHippa code that you will see above,
except UpdHeadFoot which is for updating Header/Footer section for each
document. While I am watching the directory I can see that all the temporary
~$R)….files will be created and after a few second will be eliminated after
the printout was spooled for the printer. For the first round I have no
problem and all my 4-5 documents will be printed with no problem. But after
eliminating the temporary ~$R)… files and spooling the printouts I don’t see
the Winword on the Task manager Applications window tab but I still can see
the WinWord running on the Task manager Processes tab. Now if I do the same
act of double clicking on the same Word template .dot I will get the
following dialog error:
Run-time error ‘5151’;
Word was unable to read this document. It may be corrupt.
Try one or more of the following:
*Open and Repair the file.
*Open the file with the Text Recovery converter.
Now if I terminate the Process tree for the WinWord thru the task manager
then I would be able to run and print my documents one more time without any
error dialog but the second time I have the same problem. Basically between
each print I have to terminate the WinWord thru the task manager to be able
to get the next round of printing! Looking at the directory of my word
templates on the “Date Modified†field I don’t see any changes/corruption
that may have been applied to my Word templates, so accidental corruption is
out of picture.
Question: Why won’t WinWord does not terminate even though I explicitly
close the documents? How can I force this termination thru the VBA macro