Adding my own button to the toolbar

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to add my own designed button to the toolbar, which launches a macro to show some templates to pick from. I try to do this with an add-on. I did that for a menu-item and that works correctly. However, adding a button this way, doesn't work. Whenever I start Powerpoint, the assigned macro has disappeared, the buttonimage has vanished and only a grey non-working button is visible
How can I achieve this?
 
Is the menu item creation routine invoked in the auto_open routine of the
add-in? Is the add-in loaded?

--
Regards
Shyam Pillai

http://www.mvps.org/skp

Cor van der Bliek said:
I want to add my own designed button to the toolbar, which launches a
macro to show some templates to pick from. I try to do this with an add-on.
I did that for a menu-item and that works correctly. However, adding a
button this way, doesn't work. Whenever I start Powerpoint, the assigned
macro has disappeared, the buttonimage has vanished and only a grey
non-working button is visible.
 
That's what I'm trying to achieve. The add-in is indeed loaded. The knop macro is a simulation of the
button creation with a specific image on it.

Here's what I think the problem is, if I understand you correctly:

Your Auto_Open routine runs at startup and creates the button
Your Auto_Close routine deletes it

Nothing in Auto_Open applied the button icon you want, so it's a gray button.
You may have applied it once while testing, but the Auto_Close deleted it.

Try adding something like this to Auto_Open after creating/naming NewControl

(watch line breaks)

' First start a new presentation
Dim oSh as Shape
Set oSh = Call
ActiveWindow.Selection.SlideRange.Shapes.AddPicture(FileName:="E:\Internet\Westerscheldetunnel\logoicon.
gif", _
LinkToFile:=msoFalse, _
SaveWithDocument:=msoTrue, _
Left:=353, Top:=263, Width:=14, Height:=14)

osh.Copy
NewControl.PasteFace
oSh.Delete
' and close the presentation

This is what it reads:

Sub Auto_Open()
'
' De macro is opgenomen op 11-5-2004 door C. van der Bliek.
'

Dim NewControl As CommandBarControl

' Store an object reference to a command bar.
Dim FileMenu As CommandBars

' Figure out where to place the menu choice.
Set FileMenu = Application.CommandBars

' Create the menu choice. The choice is created in the first
' position in the Tools menu.
Set NewControl = FileMenu("File").Controls.Add _
(Type:=msoControlButton, _
Before:=2)

' Name the command.
NewControl.Caption = "WST sjablonen"

' Connect the menu choice to your macro. The OnAction property
' should be set to the name of your macro.
NewControl.OnAction = "ToonSjablonen"

End Sub
Sub Auto_Close()

Dim oControl As CommandBarControl
Dim FileMenu As CommandBars

' Get an object reference to a command bar.
Set FileMenu = Application.CommandBars

' Loop through the commands on the tools menu.
For Each oControl In FileMenu("File").Controls

' Check to see whether the comand exists.
If oControl.Caption = "WST sjablonen" Then

' Check to see whether action setting is set to ChangeView.
If oControl.OnAction = "ToonSjablonen" Then

' Remove the command from the menu.
oControl.Delete
End If
End If
Next oControl

End Sub

Sub knop()
'
' De macro is opgenomen op 11-5-2004 door C. van der Bliek.
'
ActiveWindow.Selection.SlideRange.Shapes.AddPicture(FileName:="E:\Internet\Westerscheldetunnel\logoicon.
gif", LinkToFile:=msoFalse, SaveWithDocument:=msoTrue, Left:=353, Top:=263, Width:=14,
Height:=14).Select
 
I can't figure this out Steve. I tried but nothng happens, no new button at least
Where is the link with the macro (ToonSjablonen), which should be activated by pressing the new button
P.S. ToonSjablonen is Dutch for Show Templates
 
I can't figure this out Steve. I tried but nothng happens, no new button at least.

Have you made an Add-in of this, or are you just running the code from within the VBA Editor?
Where is the link with the macro (ToonSjablonen), which should be activated by pressing the new button.
P.S. ToonSjablonen is Dutch for Show Templates

This line in your code tells PowerPoint to run the subroutine "ToonSjablonen" when you click the
button:

NewControl.OnAction = "ToonSjablonen"

You need to have a Sub ToonSjablonen() in the same add-in or presentation for PPT to be able to
find it.


Here's what I think the problem is, if I understand you correctly:

Your Auto_Open routine runs at startup and creates the button
Your Auto_Close routine deletes it

Nothing in Auto_Open applied the button icon you want, so it's a gray button.
You may have applied it once while testing, but the Auto_Close deleted it.

Try adding something like this to Auto_Open after creating/naming NewControl

(watch line breaks)

' First start a new presentation
Dim oSh as Shape
Set oSh = Call
ActiveWindow.Selection.SlideRange.Shapes.AddPicture(FileName:="E:\Internet\Westerscheldetunnel\lo
goicon.
gif", _
LinkToFile:=msoFalse, _
SaveWithDocument:=msoTrue, _
Left:=353, Top:=263, Width:=14, Height:=14)

osh.Copy
NewControl.PasteFace
oSh.Delete
' and close the presentation
This is what it reads:

Sub Auto_Open()
'
' De macro is opgenomen op 11-5-2004 door C. van der Bliek.
'

Dim NewControl As CommandBarControl

' Store an object reference to a command bar.
Dim FileMenu As CommandBars

' Figure out where to place the menu choice.
Set FileMenu = Application.CommandBars

' Create the menu choice. The choice is created in the first
' position in the Tools menu.
Set NewControl = FileMenu("File").Controls.Add _
(Type:=msoControlButton, _
Before:=2)

' Name the command.
NewControl.Caption = "WST sjablonen"

' Connect the menu choice to your macro. The OnAction property
' should be set to the name of your macro.
NewControl.OnAction = "ToonSjablonen"

End Sub
Sub Auto_Close()

Dim oControl As CommandBarControl
Dim FileMenu As CommandBars

' Get an object reference to a command bar.
Set FileMenu = Application.CommandBars

' Loop through the commands on the tools menu.
For Each oControl In FileMenu("File").Controls

' Check to see whether the comand exists.
If oControl.Caption = "WST sjablonen" Then

' Check to see whether action setting is set to ChangeView.
If oControl.OnAction = "ToonSjablonen" Then

' Remove the command from the menu.
oControl.Delete
End If
End If
Next oControl

End Sub

Sub knop()
'
' De macro is opgenomen op 11-5-2004 door C. van der Bliek.
'
ActiveWindow.Selection.SlideRange.Shapes.AddPicture(FileName:="E:\Internet\Westerscheldetunnel\lo
goicon.
gif", LinkToFile:=msoFalse, SaveWithDocument:=msoTrue, Left:=353, Top:=263, Width:=14,
Height:=14).Select
ActiveWindow.Selection.Copy
Application.CommandBars("Standard").Controls.Add Type:=msoControlButton, Before:=1
End Sub


--
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================
Featured Presenter, PowerPoint Live 2004
October 10-13, San Diego, CA www.PowerPointLive.com
================================================
 
I finally got it working. Only partly though and strange things happen. My Add-in is
there, but not showing in the list

Which list? The one in Tools, Addins? If it's not there, it's not loaded.
and the button only works when I start with the blank presentation.dot.

No fair trying to confuse an old guy. That's too easy! Like shooting fish in a barrel. I
wake up confused! ;-) Blank Presentation.DOT??? Do you mean Blank Presentation.PPT?

It sounds as though you've saved your code to a file called Blank Presentation, not to an
addin; that would explain why the presentation has to be open in order for the code to run.
Adding the same auto_open and auto_close macro's to the existing presentation doesn't help
either.

No ... those subroutines only run when they're part of an Add-in, not when part of a PPT or
POT file.

Have you followed all of the steps here:

Create an ADD-IN with TOOLBARS that run macros
http://www.rdpslides.com/pptfaq/FAQ00031.htm


--
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================
Featured Presenter, PowerPoint Live 2004
October 10-13, San Diego, CA www.PowerPointLive.com
================================================
 
Back
Top