Macro Execution Error

K

Ken Allen

This one is simply weird.

One of our divisions is sending out review documents asking for individuals
in other parts of the company to perform a review of changes to parts of our
system. To facilitate this process, they developed a WORD document that
contains a list of some of the features and links to internal files and web
pages that contain some of the changes. Sections that are changed were
identified with a red question mark.

To make it easier to track, they decided that they wanted to convert the
document to a form so the user could enter review information. To keep it
simple, they decided to replace the red question marks with a dropdown that
listed the review options (to be reviewed, accepted and rejected, for
example). The links were to be wrapped inside a MACROBUTTON so the reviewers
could double-click on them to open the link. A read-only text file was to be
added to the top of the document, and each of the dropdowns was to have an
exit macro that would count the number of dropdowns and thir state (which
entry was selected) and put the metrics in the read-only edit field. The
assumption was that the reviewers do not use templates, and so all of the
code must be within the document itself. To make things a bit more
complicated, the people writing the review document did not want to bother
with the 'form' until the last moment, so they wanted a macro that would
accept a document with the red question marks and hyperlinks and
automatically convert it to a form with the proper fields and macros.

I developed a ReviewDocument.dot template file that was to be used to
develop the initial WORD document. This template contains two macros: one is
a dummy for the exit handler on the dropdowns to be created; and one that
converts the document -- replaces the red question marks with dropdown
fields; enbeds the HYPERLINKS inside MACROBUTTON fields; creates a read-only
edit field centered at the head of the document; and creates the required
macros inside the document itself. For the most part this works, as the
(protected) document can be sent to some systems as a form document and it
works as expected.

When we send the document to some systems, however, we get an unexpected
error. I know about the macro enabling issue, and we are past that -- the
file does ask if the macros are to be enabled when we open it, and we select
"Yes".

The problem occurs when the user selects one of the dropdown fields and
changes an entry. On tabbing out of the field or clicking somewhere else in
the document, the VBE window is displayed with the code for the macro being
executed displayed and an error dialog indicating "Compile error: Can't find
project or library". The line of code being displayed is as shown below,
with the "Str" text highlighted.

szStatus = szStatus & vbCr & Trim(Str(iCountApproved)) & " entries are
approved."


We have reinstalled Office a couple of times, including the conversion
libraries, and nothing seems to resolve this problem.

Any thoughts?

-Ken
 
J

Jezebel

Provoke the error, then in VBA go to References on the Tools menu and see
what is listed as MISSING.
 
K

Ken Allen

The 'References' entry on the 'Tools' menu is disabled until I stop the
debugger, close VBE, unprotect the document, and then edit a macro again.
When I do, I see that the DOT file that was used to create the file is
missing, which I would expect, but nothing else. There should be nothing in
the DOT that is required.

How can I programmatically sever the relationship with the DOT file? Should
this be enough?

-Ken
 
K

Ken Allen

I have modified the single macro in the template file so that nothing in the
document should reference the template at all (other than the document
itself). My conversion macro first creates all of the macros in the new
document, then converts the Hyperlinks, and then creates the Dropdowns that
reference the created macro. There should be nothing in the document that
references content in the template, yet I get the same error.

When I open the converted form document on the target system, moving the
focus away from a dropdown causes the macro to generate an exception on the
call to the Str() function. If I stop the macro executing, close the VBE,
unprotect the document, and open the VBE again, then the information on the
Tools/References dialog indicates that the "XXXX.dot" file is missing --
nothing else is reported as misisng.

Why should the execution of the macro be dependant upon the reference to the
template file that was used to create the document?

I can find no way to sever the relationship between the document and the
template!

Help!

-Ken
 

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