Link to home
Start Free TrialLog in
Avatar of aelatik
aelatikFlag for Netherlands

asked on

Late Binding to MS Word .DOT Templates

I have a problem with references in my Word Templates. In several templates there is a reference to another .DOT file. When this .DOT file is not on location or accidently delete i recieve a " Compile Error in hidden Module". I already know that i can't trap this error because it happens before code execution. So that leaves me one question to ask.

Is it possible to use late binding on MS Word .DOT files so i can trap these errors ?
Avatar of Brian Mulder
Brian Mulder
Flag of Netherlands image

Hello aelatik,

i think not, the error is occurring pretty deep in the chain

maybe not the fastest but the most reliable way to solve this would be at the root of the problem

- if you put a check in the dot file that looks if the needed links are available
- then handles this error and closes if needed
- the calling vb application can then handle that error if it cannot create the file

hope this helps a bit
bruintje
Avatar of aelatik

ASKER

I was already hoping to get a response from you bruintje ( Office Guru ).
I have tested this by making 2 .DOT files and referring from 1 to another.
When i move or rename the file i have referenced to i get a compile error. So i think it checks upon execution and therefore i cannot trap the error.
Notice that i have referenced the .DOT file with "Tools > References" in VBA Editor ( So its a hard reference ).

So the problem is as follows. I stated 2 templates here but in fact be have above 50 templates that reference to eachother.
If the client accidently deletes or renames one of these templates they get a " Compile Error in hidden module....".
The best way for me would be to use "Late Binding" ( if possible ). In that case i would know which file was missing.

Also, you stated : "maybe not the fastest but the most reliable way to solve this would be at the root of the problem"
How would i do that if no sub, event or function is triggered ?

Thanks for you response...
ASKER CERTIFIED SOLUTION
Avatar of Brian Mulder
Brian Mulder
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of aelatik

ASKER

OK, That seems clear enough. I have the following now :

   Dim vbProj As VBProject
   Set vbProj = ActiveDocument.VBProject
         vbProj.References.AddFromFile("C:\test\Tools.dot")

'There is a function called DoMessage in there, how do i call it now ?
'Previously i did "general.DoMessage", but that won't work anymore....

   
not sure what DoMessage is, is that a custom function in VB? there is a DoEvents

maybe i'm missing the whole picture, you are running this from Word itself or from VB using word templates
Avatar of aelatik

ASKER

For example, i have the following :

Test1.DOT ( containing 1 module and 1 function )
  - Module
      Public Function DoMessage()
        msgbox "Test"
      end function

and i have :

Test2.DOT
     Sub AutoExec()
         Dim vbProj As VBProject
         Set vbProj = ActiveDocument.VBProject
         vbProj.References.AddFromFile("C:\Test1.DOT")
         Call ???.DoMessage
     end Sub

So the question is, how do i call the DoMessage function with a reference added like above ?
I'm only using the VBA Editor that is shipped with MSOF.