Unexpected add-in toolbar behavior

C

caten

Using these resources (http://www.pptfaq.com/FAQ00031.htm and
http://support.microsoft.com/kb/q163461/) for guidance, I have successfully
created, compiled, added, tested, and used an add-in that creates a toolbar
and several buttons which access various macros. I have read that PowerPoint
will unload my add-in when I exit PowerPoint and that in order to load it
again the next time I start PowerPoint, I must use one of the 4 methods
described here: http://support.microsoft.com/kb/q222685/ .

This is not the behavior I see, however, in PowerPoint 2000 SR1 or in
PowerPoint 2002 SR3. My add-in remains loaded until I manually unload it. I
have checked the registry and although I see a key for a different add-in, I
do not see one for mine. Is this supposed to be possible?

Further, given this behavior, now I want to be able to delete my toolbar
when my add-in is unloaded but *not* every time I exit PowerPoint. I had put
a command to delete my toolbar in the Auto_Close subroutine, but then it runs
every time I exit PowerPoint. Is there a similar Auto_Unload type of thing
that I can use or create?

Finally, is there any way to make my toolbar's visibility property persist
through exiting and restarting PowerPoint? If I open the built-in Picture
toolbar and then exit PowerPoint, it is visible when I restart PowerPoint.
Likewise, if I close the built-in Picture toolbar and then exit PowerPoint,
it is closed when I restart PowerPoint. But using the visibility property in
the Auto_Open subroutine overrides whatever the toolbar's previous visibility
setting might have been (even if I do not specify the toolbar's visibility
property, it defaults to not visible).

Thank you for any suggestions or pointers to other resources.
 
C

caten

It seems to me that the strategy of having the toolbar created by the add-in
during by Auto_Open is not compatible with persistence of any toolbar
properties. If the toolbar is created each time PowerPoint starts, it will
always have the same properties (either those set explicitly or the default
values, but never whatever the most recent settings were), right?

Is there another way to create a toolbar that is more persistent? I have
tried removing the Auto_Close entirely, but even then the toolbar is
re-created each time PowerPoint starts (despite my having included an Exit
Sub for an error indicating that the toolbar already exists). I have tried
NOT setting the Visibility property, but then the toolbar is always invisible
when PowerPoint starts.

Here's the add-in code I'm using (relevant portions):

Static Sub Auto_Open()
Dim oToolbar As CommandBar
Dim oButton As CommandBarButton
Dim strMyToolbar As String

' Give the toolbar a name
strMyToolbar = "MyToolbar"

On Error Resume Next

Set oToolbar = CommandBars.Add(Name:=strMyToolbar, _
Position:=msoBarFloating, Temporary:=True)
If Err.Number <> 0 Then
MsgBox "Error number and description = " & vbCrLf _
& Err.Number & ": " & Err.Description
Exit Sub
End If

On Error GoTo ErrorHandler

Set oButton = oToolbar.Controls.Add(Type:=msoControlButton)
With oButton
.TooltipText = "Set Document Properties"
.Caption = "Set Doc Props"
.OnAction = "SetDocProps"
.Style = msoButtonIcon
.FaceId = 487 'info icon
End With

Set oButton = oToolbar.Controls.Add(Type:=msoControlButton)
With oButton
.TooltipText = "Unload the Add-In"
'.TooltipText = "Unload the " & strMyToolbar
.Caption = "Unload Add-In"
.OnAction = "UnloadAddin"
.BeginGroup = True
.Style = msoButtonIcon
.FaceId = 1640 'exit door icon
End With

oToolbar.Top = 150
oToolbar.Left = 150
oToolbar.Visible = True

NormalExit:
Exit Sub

ErrorHandler:
MsgBox Err.Number & vbCrLf & Err.Description
Resume NormalExit:

End Sub

Sub Auto_Close()

Call DeleteToolbar

End Sub


Sub DeleteToolbar()
Dim oToolbar As CommandBar

Set oToolbar = Application.CommandBars("MyToolbar")

oToolbar.Visible = False
oToolbar.Delete

End Sub

Sub UnloadAddin()
Dim oAddin As Addin
Dim Msg, Style, Title, Response

Set oAddin = Application.Addins("MyToolbar")

Msg = "Are you sure you want to delete this toolbar " _
& vbCrLf & "and unload the add-in?" _
Style = vbOKCancel + vbQuestion + vbDefaultButton1
Title = "Unload Add-In?"

On Error Resume Next

Response = MsgBox(Msg, Style, Title)
If Response = vbOK Then
'Call DeleteToolbar 'Moved to Auto_Close()
oAddin.Loaded = msoFalse
'Addins.Remove "MyToolbar" 'Decided only to unload, not remove
End If

End Sub
 
C

caten

Okay, I understand what you're saying, but your recommended solution also
seems to remove desired behavior. The only way I know to ensure that the
toolbar is deleted when the add-in is unloaded, is to delete the toolbar in
the Auto_Close (which runs not only when the add-in is unloaded but also
every time PowerPoint exits). Unfortunately, as you already informed me,
there is no "on_unload" separate from the Auto_Close. Thus, if I do NOT
delete the toolbar in the Auto_Close and I manually unload the add-in (Tools
Add-Ins > Unload), the toolbar remains but does not work. Is there another
way around this problem?
 
C

caten

Steve Rindsberg said:
You might want to try enumerating the Windows collection (via API calls) during
the Auto_Close event. If the Tools, Add-Ins window (I forget its name) is open,
then the user is removing add-ins and since your Auto_Close event fired, yours
is one of them. Otherwise, leave the toolbar there.



-----------------------------------------
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================

This sounds like it would accomplish what I want, but the Add-Ins built in
dialog box does not seem to be part of the Application.Windows collection
(which seems to include only document windows).

I put this in the Auto_Close...

With Application.Windows
For i = 1 To .Count
MsgBox ".Item(i).Caption = " & .Item(i).Caption
Next 'i
End With

....and then manually unloaded the add-in, but the only window caption
returned was the file name of the open PowerPoint presentation (not
"Add-Ins").

How can I "talk to" the Add-Ins (or any built in) dialog box?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top