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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cannot call function residing on an unaccessible template

Status
Not open for further replies.

filipne

MIS
Feb 3, 2008
5
Hi,

I do not seem to find a solution for the following:

I need to have VBA code on a document based on a certain template that verifies whether the template is available and if its it should call a Sub from it(the template).

In the document I have code that can detect a missing reference (in this case the template) and I have a call to a function from the template in case the template is available.

The thing is that whenever the template is unavailable, I get compile error at the row where the call to the template's function is made. This is a compile error not execution error. Template availability check code works fine and detects the absence of the template.

I noticed that when the template is not available Thisdocument.Attachedtemplate shows to be changed from the missing template's name to Normal.dot. Indeed, Normal.dot appers in the reference list of the Document's project along with "MISSING:" + the missing template name.


Any help is greatli appreciated!
 
It would be easier if you showed the code but I'm guessing you have a standard VBA Call statement to a non-existent procedure. One way round it would be to have a separate VBA procedure that does the call, something like (pseudocode) ...

Code:
If Template exists
    Call Procedure_2
Else
    Do whatever
Endif

Sub Procedure_2
    Call TemplateFunction
End Sub

This way, procedure_2 won't be compiled unless the Template exists.

Another way would be to use Application.Run, which wouldn't check for existence until actually executed.

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

I'm working (slowly) on my own website
 
Good answer Tony.

"I noticed that when the template is not available Thisdocument.Attachedtemplate shows to be changed from the missing template's name to Normal.dot. "

Yes, that is correct. ALL Word documents have a template attached. All of them. If Word can not find the template the document says is its AttachedTemplate, then it attaches the local Normal.dot.

It also logs/notes that the stated AttachedTemplate has not be found, and thus puts it as "Missing".

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top