I sent this reply on Tuesday, but it never appeared in the group:
Thanks, all. I also deleted the Dim myFlag = False as Mark suggested.
For anyone who's interested, here's the final result. While I have many
macros using For Each, I had never known how to determine if something
was simply in a collection or not. The first part determines whether
it's in the collection. Then I run the second part of the macro which
takes one action or another depending on the result of the first part.
This macro was also tricky because of the double stage involved in
installing a global: first adding it to the collection, then installing
it. I found it was easier, instead of having it in the collection all
the time and either installing or unstalling, to do both steps each
time, so it's either in the collection and installed, or not in the
collection.
Dim myTemplate As AddIn
Dim myFlag As Boolean
Dim FixContext As String
FixContext = "C:\Program Files\Microsoft
Office\Templates\FixContext97.dot"
System.Cursor = wdCursorNormal
' Determine if FixContext is in AddIns collections.
For Each myTemplate In AddIns
If myTemplate.Name = "FixContext97.dot" Then
myFlag = True
Exit For
End If
Next
' If FixContext is not in collection, add it.
If myFlag = False Then
If MsgBox("FixContext template is currently NOT INSTALLED as Global."
_
& vbCr & "INSTALL now.", vbOKCancel, _
"Toggle FixContext Template as Global") = vbOK Then _
AddIns.Add FileName:=FixContext, Install:=True
Else
' If FixContext is in collection, delete it.
If MsgBox("FixContext template is currently INSTALLED as Global." _
& vbCr & "UNINSTALL now.", vbOKCancel, _
"Toggle FixContext Template as Global") = vbOK Then _
AddIns(FixContext).Delete
End If