Results 1 to 15 of 15
  1. #1
    Star Lounger
    Join Date
    Jan 2001
    Location
    New York, New York, USA
    Posts
    84
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Macro for loading templates and addins

    Using Word 2000 on Windows 2000. I've created a toolbar button which calls a macro that loads a template so that it will show the template's toolbar. The button works like a toggle to close the toolbar as well, but I can't find a way to actually UNload the template (i.e., so that it's not checked in the templates and addins dialog). This is desirable since this particular template is in conflict with one of our global templates (overriding some of its menu items). Below is my code. I hope one of you gurus out there can help me figure this one out. Thanks very much.

    Public Sub ShowWestCheckButton()
    Dim iAddInCnt As Integer, sAddInName As String
    Dim iCnt As Integer, bToolBarFound As Boolean
    Dim bShowToolBar As Boolean, bcShowToolBar As Boolean
    Dim sSecondaryTemplates$

    On Error GoTo ErrorRoutine
    sSecondaryTemplates$ = Environ("userprofile")

    sSecondaryTemplates$ = sSecondaryTemplates$ & "Application DataMicrosoftAddins"
    iCnt = 1
    iAddInCnt = AddIns.Count

    Do While iCnt <= iAddInCnt
    sAddInName = AddIns.Item(iCnt).Name
    If sAddInName = "West Group Westcheck.dot" Then
    bToolBarFound = True
    Exit Do
    Else
    iCnt = iCnt + 1
    End If
    Loop

    If bToolBarFound = True Then
    bShowToolBar = CommandBars("Westcheck").Visible

    AddIns(sSecondaryTemplates$ & "West Group Westcheck.dot").Installed = True
    bcShowToolBar = CommandBars("Westcheck").Visible
    ActiveDocument.UpdateStylesOnOpen = False

    If bShowToolBar = False And bcShowToolBar = True Then
    'Just Position, it's already visible
    CommandBars("Westcheck").Position = msoBarTop
    CommandBars("Westcheck").Left = 100
    CommandBars("Westcheck").Top = 104
    ElseIf bShowToolBar = True And bcShowToolBar = True Then
    CommandBars("Westcheck").Visible = False
    ElseIf bShowToolBar = False And bcShowToolBar = False Then
    CommandBars("Westcheck").Visible = True
    CommandBars("Westcheck").Position = msoBarTop
    CommandBars("Westcheck").Left = 100
    CommandBars("Westcheck").Top = 104
    End If
    Else
    AddIns.Add FileName:=sSecondaryTemplates$ & "West Group Westcheck.dot", Install:=True
    ActiveDocument.UpdateStylesOnOpen = False
    CommandBars("Westcheck").Visible = True
    End If
    Exit Sub
    ErrorRoutine:
    If Err.Number = 5180 Then
    MsgBox "Word cannot open this document template." + Chr(13) + Chr(13) + "The Template being sought may not be" + Chr(13) + "resident in the Word template Directory.", 48, "Word cannot open . . ."
    ElseIf Err.Number = 5 Then
    Err.Clear
    Resume Next
    Else
    MsgBox "Error Number " & Err.Number & " Has Occurred " + Chr(13) + Error
    End If
    End Sub

  2. #2
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Macro for loading templates and addins

    I've just recorded a macro of my going into the Templates and Add-Ins dialog and unloading one of the addins that was checked there.
    The resultant code:

    AddIns("D:WordData97TemplatesMeBmkBrowser.dot").In stalled = False


    Does this help?

  3. #3
    Star Lounger
    Join Date
    Jan 2001
    Location
    New York, New York, USA
    Posts
    84
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macro for loading templates and addins

    <img src=/S/smile.gif border=0 alt=smile width=15 height=15> Yes, it worked!! I just had to find the right spot to put it. Thank you very much.

  4. #4
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Vancouver, BC
    Posts
    139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macro for loading templates and addins

    I'm looking for how to go the other way. How do I load an add-in (from a LAN directory)? Schatzie's code looks to me as if the add-ins are there and that program is looking for a particular one. Would
    AddIns("L:TemplatesTemplateName.dot").Installed = True
    add it?

  5. #5
    kelliel
    Guest

    Re: Macro for loading templates and addins

    Yup.

    Form Schatze's original post, this line

    <pre>AddIns(sSecondaryTemplates$ & "West Group Westcheck.dot").Installed = True</pre>


    is the one that loads the template.

  6. #6
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Vancouver, BC
    Posts
    139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macro for loading templates and addins

    I actually tried that. In my AutoNew, I coded:
    AddIns("L:TemplatesProjectWatermark2.dot").Install ed = True

    I also tried running it once the new document was open, in case it just can't do it as an AutoNew. In both cases, on other computers, I got "Runtime error '5941' The requested member of the collection does not exist". I copied the template location from the code into the find command and it found the file, so the location is correct and everyone's drive mapping is the same. It works OK on my own computer, but I think that's because I manually attached that template once (and can untick it but the delete button is not available to remove it). I need to have it work for other people on the LAN though. Do I have to do something to attach it before I can say installed=true?

    I also tried
    AddIns("L:TemplatesProjectWatermark2.dot").Autoloa d = True
    but that got a compile error: Can't assign to a read only property.

  7. #7
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Macro for loading templates and addins

    If the add-in is not already in the add-ins collection, you use the Add method to add it. <img src=/S/wink.gif border=0 alt=wink width=15 height=15>

    AddIns.Add FileName:="L:TemplatesProjectWatermark2.dot", _
    Install:=True

    Now, there must be a way to see if the add-in already has been added but, if not, you could use On Error to handle it:

    On Error Goto addWatermarkDot
    AddIns("L:TemplatesProjectWatermark2.dot").Install ed = True
    On Error Goto 0
    WatermarkDotInstalled:
    ...

    addWatermarkDot:
    AddIns.Add FileName:="L:TemplatesProjectWatermark2.dot", _
    Install:=True
    Resume WatermarkDotInstalled

  8. #8
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Macro for loading templates and addins

    Hi Wendy,

    "Installed = True" is equivalent to already having the add-in showing in the Templates and Add-Ins dialog (but unchecked), and "checking" the checkmark.

    Before Installing it, you need to add it to the AddIns collection (that's why you're getting the error). You can do it this way:

    AddIns.Add ("L:TemplatesProjectWatermark2.dot")

    But VBA helps demos a method to Add and Load it in one swoop:

    AddIns.Add FileName:="C:Program FilesMicrosoft Office" _
    & "TemplatesLetters & FaxesMyFax.dot", Install:=True

    Gary

  9. #9
    Star Lounger
    Join Date
    Jan 2001
    Location
    New York, New York, USA
    Posts
    84
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macro for loading templates and addins

    I got the same error message ("The requested member of the collection does not exist") when trying to run the macro under a different userprofile on the same Windows 2000 PC. The problem turned out to be one of permissions. The clue was that the macro worked for some profiles but not for others even though the file was in a common location (c:Program Files path).

    Permissions are very complicated and I don't completely understand them. Apparently, the rights were broken for some users, even though the security dialog seemed to indicate that the "everyone" group should have had "read and execute" and "read" rights to the target template. There is an additional issue of "inheritable permissions from parent" which further complicates things. I had to ask one of my IT colleagues to straighten this out; but you may want to check into this possibility.

  10. #10
    kelliel
    Guest

    Re: Macro for loading templates and addins

    Sorry for giving you the bum steer!

    This is the code we use in all our our normal.dot.

    <pre> AddIns.Add FileName:="g:forms97cmt.dot", Install:=True
    </pre>


  11. #11
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Vancouver, BC
    Posts
    139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macro for loading templates and addins

    YES, yes, yes. Addin.Add worked on my machine and it worked on another machine that had never seen that addin before. And it worked when I already had the addin loaded and installed, Jefferson, so the coding to handle it when it's already been loaded doesn't seem to be required.

    So that means I can move my common routines to a separate template and just put the Add code in the individual templates. Now to see whether all that's required is to have the Add code in the template on which the other templates are based.

  12. #12
    kelliel
    Guest

    Re: Macro for loading templates and addins

    Glad it worked for you. <img src=/S/thumbup.gif border=0 alt=thumbup width=15 height=15>

  13. #13
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Vancouver, BC
    Posts
    139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macro for loading templates and addins

    Jefferson, now I see what you mean about it being a good idea to check if it's already installed. But On Error won't do it, because it's not an error if it's already installed. It just installs it again, so you have it however many times you've installed it. That's what's not such a good idea.

    I haven't figured out how to check if a particular addin is installed. Do I really have to read through all the addins to see if each one matches the one I'm looking for? I don't even know how to do that. So much for pulling my code out of each template and putting it in a common template. I almost have as much code to just ADD IN the common template as I had IN the common template.

  14. #14
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Vancouver, BC
    Posts
    139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macro for loading templates and addins

    I think I have the answer to checking if the addin is already there:
    intAddInCount = AddIns.Count
    For X = 1 To intAddInCount
    If AddIns.Item(X) = "TemplatesMacroCode.dot" Then
    booAddInFound = True
    End If
    Next X

  15. #15
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Macro for loading templates and addins

    Wendy,

    This method of checking is the way to find out if a member of a collection already exists - when you need to find out whether it exists before you can safely reference it - another example of a use for this is in checking whether a style exists in a document.

    You'll find that this will run a lot faster though if you use a For Each...Next construct to loop through the Addins collection.

    (without having tested this
    Public Function booAddInFound(strName As String) As Boolean
    Dim tAddIn As AddIn
    For Each tAddIn In AddIns
    If tAddIn.Name = strName Then
    booAddInFound = True
    Exit Function
    End If
    Next tAddIn
    End Function

    Gary

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •