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

Closing used template from file...

Status
Not open for further replies.

JadeKnight

IS-IT--Management
Feb 23, 2004
94
NO
Hi, I've got a problem with a couple of macros. Our company has just changed from Office97 to Office 2003, and our old templates/macroes are obsolete.

I have corrected most of it, but I do have a little problem. I have one template, let's call it X wich is using code from a "master" template. Let's call it common. This is working fine until we close the document. If we try to create a new, we recieve an error that says that the macro doesn't exist. The common template is still open. However, if we close Word, and start with a new document, this works fine.

I'm pretty familiar with VBscript, but this isn't my domain. I assume that there is a way to close the open common template. Any help would be appreciated :)...

Here's the code :

Constants defined in Modules :

Public Const coMainDotFile As String = "Common.dot"
Public Const coMainDotFileNamePath As String = "C:\temp\Common.dot"

ThisDocument
Code:
Option Explicit
Private Sub Document_Close()
    Call byttTilGammelSkriver(ActiveDocument.AttachedTemplate)
End Sub

Private Sub Document_New()
    On Error GoTo err_trap
    Dim lTeller As Long
    Dim bFunnet As Boolean
    
    bFunnet = False
    For lTeller = 1 To AddIns.Count
        If AddIns.Item(lTeller).Name = coMainDotFile Then
            bFunnet = True
            Exit For
        End If
    Next lTeller
    
    If Not bFunnet Then
        Call AddIns.Add(coMainDotFileNamePath, True)
        lTeller = AddIns.Count
    Else
        AddIns(lTeller).Installed = True
    End If
    
    Call AddIns(lTeller).Application.Activate
    
    frmFillIn.Show
    Call byttSkriver(ActiveDocument.AttachedTemplate)
    
    Exit Sub
err_trap:
    Resume Next
End Sub



 
Found solution to the problem, thought I should share it with the rest of you guys :)

Add this line to : Private Sub Document_Close()

Code:
Private Sub Document_Close()
    Call byttTilGammelSkriver(ActiveDocument.AttachedTemplate)
    If AddIns.Count > 0 Then AddIns.Unload RemoveFromList:=False
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top