PDA

View Full Version : Solved: Preventing an Addin from loading more than once



AndrewPerl
11-29-2005, 03:33 PM
I wrote the following macro to set some options and then load an addin and a custom dictionary. The problem is that during testing the addin is loaded more than once. This also causes the toolbar which is part of the addin (just a template) to load repeatedly. Is there some way I can check to see if the Addin is already loaded so I can skip this part of the code.

Private Sub Document_Open()
'Set path variable for template location
Const WGTemplatePath = "W:\Office Templates"
'Set path variable for dictionaries
Const WGDictPath = "W:\office Templates\Template Resources\Dictionaries\"
'Set variable for name of TA2000 dictionary
Const TADICTName = "TA2000 Dictionary.dic" 'name of custom TA2000 dictionary
'Set variable for writing style (options are "GRAMMAR" and "GRAMMAR & STYLE")
Const WriteStyle = "Grammar & Style"
'Set variable to complete building pathname for SES_Macros.dot addin.
Const SESMacrosPath = "\Project Documentation\SES_Macros.dot"
'Set the workgroup templates path to W:\CORPCOMM\CMS Template Files
MsgBox "Click OK to set the Workgroup Template path. This may take a few seconds."
Options.DefaultFilePath(wdWorkgroupTemplatesPath) = WGTemplatePath

'Set various Word environment variables
Options.AllowFastSave = False 'Turn off Fast Saves;reduces chances of file corruption
Options.Overtype = False 'Turn off Overtype mode;just plain annoying
Options.PromptUpdateStyle = False 'Do not allow users to update styles;just reapply current style to selection
Options.SaveInterval = 10 'Save current document every ten minutes
Options.UpdateFieldsAtPrint = False 'Do not updates fields when printing
Options.UseCharacterUnit = False 'Do not use character unit;use inches instead

'Set the writing style to check grammar and style
Languages(wdEnglishUS).DefaultWritingStyle = WriteStyle

'Install the TA2000 dictionary
CustomDictionaries.Add FileName:=WGDictPath & TADICTName

'Install the SES_Macros template as an AddIn and ensure it is installed

AddIns.Add FileName:=WGTemplatePath & SESMacrosPath, Install:=True


End Sub


Any help on this would be greatly appreciated.

Thanks,

Andrew in Kansas City

AndrewPerl
11-30-2005, 10:43 AM
I added this code to the macro and got it working. The code uses a For Next loop to check all loaded Addins. I check the name and see if it matches my Addin template name (SES_Macros.dot). You have to be aware that just because an Addin is in the list doesn't mean it is installed. That is why I added the check for the .Installed property to the IF statement.

I ran this multiple times with watches set to numerous variables. It goes through the entire list without a snag. Here is the code...


For Each oAddin In AddIns
If oAddin.Name = "SES_Macros.dot" And oAddin.Installed = True Then SESInstalled = 1
Next oAddin

If SESInstalled <> 1 Then AddIns.Add FileName:=WGTemplatePath & SESMacrosPath, Install:=True


I will now try to apply this to the dictionary loading routine.

Andrew in Kansas City