Nonsense dialog box of "Sub or Function not defined"

  • Thread starter Jeffery B Paarsa
  • Start date
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?
 
J

Jeffery B Paarsa

Finally I resolved this problem but I could never find out what was wrong! I
was using this statment of:
Set HistPhysForm =
Word.Documents.Add(Template:=Application.MacroContainer.Path + "\(MR)History
& Physical.dot", Visible:=False)
at least 10 times in my code... 8 of these statment were working but two of
them were giving me this nonsense dialog... Finally after spending more than
3-4 days of debugging working and changing the code, I decided to take one of
the working template and rename it to the problem template and only keep the
heading and footing part and delete the body of the document and then copy
the body of the problem templates only to the body area of the renamed
working template... Some how this resolved my problem and the Nonsense dialog
disapeared with out knowing what was the real problem!
 
C

Cindy M.

Hi Jeff,

VBA code has a tendency to not delete things completely when you're editing
macros. I'm guessing that may be what the problem was, although it could have
been damage in another part of the document's structure. In any case, the steps
you describe are what one does when the document's internal structures become
unstable.

There is a tool named something like "Code Cleaner" that rebuilds the code
modules to "shake out the dust" (clean out the stuff that's left over from
editing).
Finally I resolved this problem but I could never find out what was wrong! I
was using this statment of:
Set HistPhysForm =
Word.Documents.Add(Template:=Application.MacroContainer.Path + "\(MR)History
& Physical.dot", Visible:=False)
at least 10 times in my code... 8 of these statment were working but two of
them were giving me this nonsense dialog... Finally after spending more than
3-4 days of debugging working and changing the code, I decided to take one of
the working template and rename it to the problem template and only keep the
heading and footing part and delete the body of the document and then copy
the body of the problem templates only to the body area of the renamed
working template... Some how this resolved my problem and the Nonsense dialog
disapeared with out knowing what was the real problem!

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 

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