J
Jeffery B Paarsa
Hello,
I have a word template with a user form which I collect some vital info from
the dialog box/UserForm I display, then based on the checked boxes on the
userform I call in different subroutines which in those subroutines I plug in
the collected data from the user form and print different documents. A total
of 20-25 different form/documents I print based on the user selection of the
check boxes... not necessary all the check boxes are checked and all the
forms is being printed only 3-5 forms can be printed on each invokation.
I have a total of 9 subroutine and 2 Function so far in this VBA for the
user form. I will be adding at least may be 15-18 more subroutine. What is
strange is for the first 6 check boxes I have no problem and I print the
necessary Document after plugging the collected data but when I added
Subroutine for document 7 & 8 a nonsense problem started.
Here is the subroutine being executed:
====
Sub printHistPhys(ByRef PForms As UserForm)
Dim HistPhysForm As Document
Set HistPhysForm =
Word.Documents.Add(Template:=Application.MacroContainer.Path + "\(MR)History
& Physical.dot", Visible:=False)
With HistPhysForm
.Unprotect
.Bookmarks("PLName").Range _
.InsertBefore PLName
.Bookmarks("PLName").Range.Font.Color = wdColorRed
.Bookmarks("PFName").Range _
.InsertBefore PFName
.Bookmarks("PFName").Range.Font.Color = wdColorRed
.Bookmarks("PVDate").Range _
.InsertBefore PVDate
.Bookmarks("PVdate").Range.Font.Color = wdColorRed
.Bookmarks("PDOB").Range _
.InsertBefore PDOB
.Bookmarks("PDOB").Range.Font.Color = wdColorRed
.Bookmarks("AddrL1").Range _
.InsertBefore AddrL1
.Bookmarks("AddrL2").Range _
.InsertBefore AddrL2
.Bookmarks("Phone").Range _
.InsertBefore Phone
.Bookmarks("Fax").Range _
.InsertBefore Fax
.Bookmarks("WebURL").Range _
.InsertBefore WebURL
ActiveDocument.Fields.Update
.Protect wdAllowOnlyFormFields, Noreset:=True
.PrintOut
.Close wdDoNotSaveChanges
End With
End Sub
====
after checking the check box 7 & 8 or just 7 or 8 and if they have been set
I call the related subroutine, a nonsense dialog opens stating "Sub or
Function not defined" with two buttons on it one is Ok, other one is Help.
If I click Ok button subroutine executes with no problem and form/document is
being printed and If I push Help button following dialog text will be opend:
===
Word 2007 Developer Reference > Visual Basic for Applications Language
Reference > Visual Basic Language Reference > Error Messages
Sub, Function, or Property not defined (Error 35)
A Sub, Function, or Property procedure must be defined to be called. This
error has the following causes and solutions:
You misspelled the name of your procedure.
Check the spelling and correct it.
You tried to call a procedure from another project without explicitly
adding a reference to that project in the References dialog box.
To add a reference
1. Display the References dialog box.
2. Find the name of the project containing the procedure you want to call.
If the project name doesn't appear in the References dialog box, click the
Browse button to search for it.
3. Click the check box to the left of the project name.
4. Click OK.
The specified procedure isn't visible to the calling procedure.
Procedures declared Private in one module can't be called from procedures
outside the module. If Option Private Module is in effect, procedures in the
module aren't available to other projects. Search to locate the procedure.
You declared a Windows dynamic-link library (DLL) routine or Macintosh
code-resource routine, but the routine isn't in the specified library or code
resource.
Check the ordinal (if you used one) or the name of the routine. Make sure
your version of the DLL or Macintosh code-resource is the correct one. The
routine may only exist in later versions of the DLL or Macintosh
code-resource. If the directory containing the wrong version precedes the
directory containing the correct one in your path, the wrong DLL or Macintosh
code-resource is accessed. You gave the right DLL name or Macintosh
code-resource, but it isn't the version that contains the specified function.
For additional information, select the item in question and press F1 (in
Windows) or HELP (on the Macintosh).
===
I put a trace on the VB code and I noticed as soon as I come to the second
line of the code which is:
===
Set HistPhysForm =
Word.Documents.Add(Template:=Application.MacroContainer.Path + "\(MR)History
& Physical.dot", Visible:=False)
===
the nonsense dialog box appears! which if I push the Okay button then the
document is being printed with no problem... I don't know why this nonsense
dialog apperes? Do you know why?
I have a word template with a user form which I collect some vital info from
the dialog box/UserForm I display, then based on the checked boxes on the
userform I call in different subroutines which in those subroutines I plug in
the collected data from the user form and print different documents. A total
of 20-25 different form/documents I print based on the user selection of the
check boxes... not necessary all the check boxes are checked and all the
forms is being printed only 3-5 forms can be printed on each invokation.
I have a total of 9 subroutine and 2 Function so far in this VBA for the
user form. I will be adding at least may be 15-18 more subroutine. What is
strange is for the first 6 check boxes I have no problem and I print the
necessary Document after plugging the collected data but when I added
Subroutine for document 7 & 8 a nonsense problem started.
Here is the subroutine being executed:
====
Sub printHistPhys(ByRef PForms As UserForm)
Dim HistPhysForm As Document
Set HistPhysForm =
Word.Documents.Add(Template:=Application.MacroContainer.Path + "\(MR)History
& Physical.dot", Visible:=False)
With HistPhysForm
.Unprotect
.Bookmarks("PLName").Range _
.InsertBefore PLName
.Bookmarks("PLName").Range.Font.Color = wdColorRed
.Bookmarks("PFName").Range _
.InsertBefore PFName
.Bookmarks("PFName").Range.Font.Color = wdColorRed
.Bookmarks("PVDate").Range _
.InsertBefore PVDate
.Bookmarks("PVdate").Range.Font.Color = wdColorRed
.Bookmarks("PDOB").Range _
.InsertBefore PDOB
.Bookmarks("PDOB").Range.Font.Color = wdColorRed
.Bookmarks("AddrL1").Range _
.InsertBefore AddrL1
.Bookmarks("AddrL2").Range _
.InsertBefore AddrL2
.Bookmarks("Phone").Range _
.InsertBefore Phone
.Bookmarks("Fax").Range _
.InsertBefore Fax
.Bookmarks("WebURL").Range _
.InsertBefore WebURL
ActiveDocument.Fields.Update
.Protect wdAllowOnlyFormFields, Noreset:=True
.PrintOut
.Close wdDoNotSaveChanges
End With
End Sub
====
after checking the check box 7 & 8 or just 7 or 8 and if they have been set
I call the related subroutine, a nonsense dialog opens stating "Sub or
Function not defined" with two buttons on it one is Ok, other one is Help.
If I click Ok button subroutine executes with no problem and form/document is
being printed and If I push Help button following dialog text will be opend:
===
Word 2007 Developer Reference > Visual Basic for Applications Language
Reference > Visual Basic Language Reference > Error Messages
Sub, Function, or Property not defined (Error 35)
A Sub, Function, or Property procedure must be defined to be called. This
error has the following causes and solutions:
You misspelled the name of your procedure.
Check the spelling and correct it.
You tried to call a procedure from another project without explicitly
adding a reference to that project in the References dialog box.
To add a reference
1. Display the References dialog box.
2. Find the name of the project containing the procedure you want to call.
If the project name doesn't appear in the References dialog box, click the
Browse button to search for it.
3. Click the check box to the left of the project name.
4. Click OK.
The specified procedure isn't visible to the calling procedure.
Procedures declared Private in one module can't be called from procedures
outside the module. If Option Private Module is in effect, procedures in the
module aren't available to other projects. Search to locate the procedure.
You declared a Windows dynamic-link library (DLL) routine or Macintosh
code-resource routine, but the routine isn't in the specified library or code
resource.
Check the ordinal (if you used one) or the name of the routine. Make sure
your version of the DLL or Macintosh code-resource is the correct one. The
routine may only exist in later versions of the DLL or Macintosh
code-resource. If the directory containing the wrong version precedes the
directory containing the correct one in your path, the wrong DLL or Macintosh
code-resource is accessed. You gave the right DLL name or Macintosh
code-resource, but it isn't the version that contains the specified function.
For additional information, select the item in question and press F1 (in
Windows) or HELP (on the Macintosh).
===
I put a trace on the VB code and I noticed as soon as I come to the second
line of the code which is:
===
Set HistPhysForm =
Word.Documents.Add(Template:=Application.MacroContainer.Path + "\(MR)History
& Physical.dot", Visible:=False)
===
the nonsense dialog box appears! which if I push the Okay button then the
document is being printed with no problem... I don't know why this nonsense
dialog apperes? Do you know why?