PDA

View Full Version : Solved: Addins installed err 5491



shapes
11-23-2010, 02:52 AM
Hello, I am at a loss as to why I keep getting error code 5491, well I think I know why but not sure how to solve it. I need to check if a specific addin is installed when a new document is created from my template. The addin I need to check for is CFBWeb.dot, this code works fine, but if the addin CFBWeb.dot is not present, word cant recognise the string and shows error code 5491.

Private Sub Document_New()

If AddIns("M:\Templates\Office\CFB\CFBWeb.dot").Installed = True Then 'the dubugger stops here

' messagebox with text, OK-button and an information-icon

MsgBox "A question box will appear asking if you want to enable the CFB web template." _
& vbCrLf & vbCrLf & "When this box appears click NO.", vbCritical, "ATTENTION"

Else

End If

'code for showing toolbar
CommandBars("Insrt_rmove_Numbering").Visible = True
CommandBars("Insrt_rmove_Numbering").Position = msoBarTop
ActiveDocument.CommandBars("Insrt_rmove_Numbering").Protection = msoBarNoMove
ActiveDocument.CommandBars("Toolbar List").Enabled = False
ActiveDocument.CommandBars("Tools").Controls("Customize...").Enabled = False
ActiveDocument.CommandBars("Toolbar List").Enabled = False
If ActiveWindow.View.ReadingLayout = True Then
ActiveWindow.View.ReadingLayout = False
Else
End If
End Sub

I do have a dodgey solution of putting in an errhandler goto, and reuse the 'code for showing toolbar' section but there must be a better way.

macropod
11-23-2010, 04:38 AM
Hi shapes,

Try this approach:
Private Sub Document_New()
Dim bAddin As Boolean, oAddIn As AddIn
bAddin = False
For Each oAddIn In Application.AddIns
With oAddIn
If InStr(.Name, "CFBWeb") > 0 Then
bAddin = True
If oAddIn.Installed = False Then bAddin = False
Exit For
End If
End With
Next
If bAddin = True Then
'code for showing toolbar
With CommandBars("Insrt_rmove_Numbering")
.Visible = True
.Position = msoBarTop
End With
With ActiveDocument
.CommandBars("Insrt_rmove_Numbering").Protection = msoBarNoMove
.CommandBars("Toolbar List").Enabled = False
.CommandBars("Tools").Controls("Customize...").Enabled = False
.CommandBars("Toolbar List").Enabled = False
End With
ActiveWindow.View.ReadingLayout = False
End Sub
PS: I'm not sure why you have two instances of '.CommandBars("Toolbar List").Enabled = False'. I'll leave you to sort that one out.

shapes
11-23-2010, 05:56 AM
thx macro, I'll try it tommorow and let you know how I go. yes I spotted the double line when I posted it lol. your code looks neat! thanks.

shapes
11-23-2010, 07:26 PM
This seems to do what I needed, basically show the msgbox if the other .dot addin is detected to give users instructions, then show the toolbar regardless. The other .dot addin CFBWeb is a huge thing I have nothing to do with and kind of takes over word so I have to make allowances for it in my template :( Your code worked great macropod, I was pulling my hair out over this one, I think the key things I was missing were the For With statement, declaring the addin and the InStr ( a command I am not really familiar with)
:thumb :thumb
Private Sub Document_New()
'On Error Resume Next

Dim oAddIn As AddIn

For Each oAddIn In Application.AddIns
With oAddIn
If InStr(.Name, "CFBWeb") > 0 Then

If oAddIn.Installed = True Then

MsgBox "A question box will appear asking if you want to enable the CFB Web template." _
& vbCrLf & vbCrLf & "When this box appears click NO.", vbCritical, "ATTENTION"

End If
End If
End With
Exit For


Next

'code for showing toolbar
With CommandBars("Insrt_rmove_Numbering")
.Visible = True
.Position = msoBarTop
End With
With ActiveDocument
.CommandBars("Insrt_rmove_Numbering").Protection = msoBarNoMove
.CommandBars("Toolbar List").Enabled = False
.CommandBars("Tools").Controls("Customize...").Enabled = False
.CommandBars("Toolbar List").Enabled = False
End With
'ActiveWindow.View.ReadingLayout = False '<this line only seems to work in office 2003 not 2007
End Sub

macropod
11-23-2010, 09:48 PM
Hi shapes,

show the msgbox if the other .dot addin is detected
I wasn't aware that your code was processing two templates, hence the way I coded the macro.

You should re-position the ' Exit For' statement immediately after your MsgBox. Where you have it, the code will exit immediately the first Addin (which isn't necessarily the one you're interested in) is processed. If that Addin isn't the one you're interested in, but is a later one in the list, you'll never get the message.

Instr does a string search to see if the string you're interested exists within another string.

shapes
11-23-2010, 11:33 PM
Hi shapes,

I wasn't aware that your code was processing two templates, hence the way I coded the macro.

You should re-position the ' Exit For' statement immediately after your MsgBox. Where you have it, the code will exit immediately the first Addin (which isn't necessarily the one you're interested in) is processed. If that Addin isn't the one you're interested in, but is a later one in the list, you'll never get the message.

Instr does a string search to see if the string you're interested exists within another string.

ah ok Ill move that, thanks! I tested it with two dummy .dots installed as addins. works really well.