MS Office Forum / General PowerPoint Questions / October 2006
Unexpected add-in toolbar behavior
|
|
Thread rating:  |
caten - 19 Sep 2006 18:39 GMT 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.
Steve Rindsberg - 24 Sep 2006 03:37 GMT > Using these resources (http://www.pptfaq.com/FAQ00031.htm and > http://support.microsoft.com/kb/q163461/) for guidance, I have successfully [quoted text clipped - 6 lines] > This is not the behavior I see, however, in PowerPoint 2000 SR1 or in > PowerPoint 2002 SR3. Trust your eyes. <g> The author of that article may have been referring to addins loaded via other code or ... well ... something. Else.
> 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? 1) Don't peek until AFTER you've loaded the addin and then quit PPT. 2) You're looking in HKCU and not HKLM, correct?
> 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? No, afraid not.
> Finally, is there any way to make my toolbar's visibility property persist > through exiting and restarting PowerPoint? It should w/o your having to do anything. But it sounds like you're explicitly setting the Visible property in Auto_Open. That will indeed override whatever PPT is remembering.
Want to quote your Auto_Open code here for us to peek at?
> If I open the built-in Picture > toolbar and then exit PowerPoint, it is visible when I restart PowerPoint. [quoted text clipped - 5 lines] > > Thank you for any suggestions or pointers to other resources. ----------------------------------------- Steve Rindsberg, PPT MVP PPT FAQ: www.pptfaq.com PPTools: www.pptools.com ================================================
caten - 03 Oct 2006 20:52 GMT 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
> > Using these resources (http://www.pptfaq.com/FAQ00031.htm and > > http://support.microsoft.com/kb/q163461/) for guidance, I have successfully [quoted text clipped - 50 lines] > PPTools: www.pptools.com > ================================================ Steve Rindsberg - 03 Oct 2006 23:23 GMT > 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? 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. When you create the toolbar, you're setting the Temporary property to true; when you do that, the toolbar goes away when PPT shuts down. That's why it's not persistent.
A few other slight changes and there's this:
Sub Auto_Open()
Dim oToolbar As CommandBar Dim oButton As CommandBarButton Dim strMyToolbar As String
' Give the toolbar a name strMyToolbar = "MyToolbar"
' Try to get a reference to the toolbar; if you can't, it's not there ' so create it: On Error Resume Next Set oToolbar = Application.CommandBars("MyToolbar") On Error GoTo ErrorHandler If oToolbar Is Nothing Then ' it's not there; create it Set oToolbar = CommandBars.Add(Name:=strMyToolbar, _ Position:=msoBarFloating) ' BUT NOT TEMPORARY! ' No changes to your code from here to the end sub 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 End If NormalExit: Exit Sub
ErrorHandler: MsgBox Err.Number & vbCrLf & Err.Description Resume NormalExit:
End Sub
Sub Auto_Close()
'Call DeleteToolbar
End Sub
' Same trick here as above.. ' Try to get a reference to the toolbar and only delete it if reference ' is valid
Sub DeleteToolbar() Dim oToolbar As CommandBar On Error Resume Next Set oToolbar = Application.CommandBars("MyToolbar") If Not oToolbar Is Nothing Then oToolbar.Visible = False oToolbar.Delete End If End Sub
> Here's the add-in code I'm using (relevant portions): > > Static Sub Auto_Open() Why a Static sub? I don't see any reason not to do this, but neither is there any reason TO make it Static.
> Dim oToolbar As CommandBar > Dim oButton As CommandBarButton [quoted text clipped - 140 lines] > > PPTools: www.pptools.com > > ================================================ ----------------------------------------- Steve Rindsberg, PPT MVP PPT FAQ: www.pptfaq.com PPTools: www.pptools.com ================================================
caten - 09 Oct 2006 19:03 GMT 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?
Steve Rindsberg - 10 Oct 2006 01:21 GMT > 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 [quoted text clipped - 5 lines] > > Add-Ins > Unload), the toolbar remains but does not work. Is there another > way around this problem? 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 ================================================
caten - 10 Oct 2006 15:41 GMT > > 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 [quoted text clipped - 16 lines] > 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?
Steve Rindsberg - 10 Oct 2006 22:46 GMT > > > 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 [quoted text clipped - 28 lines] > Next 'i > End With This only enumerates the windows that belong to the Application (PowerPoint, that is)
You need to look at the Windows collection. As mentioned above, this will take API calls. The ability to do it isn't built directly into VB/VBA. Something along these lines might work:
Private Declare Function FindWindow _ Lib "User32" _ Alias "FindWindowA" _ (ByVal lpClassName As String, _ ByVal lpWindowName As Any) As Long
Public Function IsWindowTitle(pStrWindowTitle As String) As Boolean ' Returns True if window with specified title exists If FindWindow(vbNullString, pStrWindowTitle) > 0 Then IsWindowTitle = True Else IsWindowTitle = False End If End Function
Sub Auto_Close() If IsWindowTitle("Add-Ins") Then ' User is unloading your add-in deliberately Else ' PowerPoint is shutting down End If End Sub
----------------------------------------- Steve Rindsberg, PPT MVP PPT FAQ: www.pptfaq.com PPTools: www.pptools.com ================================================
caten - 11 Oct 2006 13:10 GMT Success! Does exactly what I want.
Thank you so much for your help, Steve.
Steve Rindsberg - 11 Oct 2006 15:59 GMT > Success! Does exactly what I want. > > Thank you so much for your help, Steve. Excellent ... glad to hear it.
----------------------------------------- Steve Rindsberg, PPT MVP PPT FAQ: www.pptfaq.com PPTools: www.pptools.com ================================================
caten - 11 Oct 2006 13:10 GMT Success! Does exactly what I want.
Thank you so much for your help, Steve.
|
|
|