Discussion:
Why is it disable for add button item
(too old to reply)
Steven
2006-09-25 08:45:34 UTC
Permalink
Hi,

I write a macro and add a button item "Hello" in powerpoint's Standard
toolbar, and assign
onAction property(a function name), after i add it, why is it disable? I
don't click it!

but if I add the buttom in "slide show" popup menu, It works, I don't know
reason! I write it with macro!

If I write code with vb, then compile it, I define "
Dim WithEvents buttonHello As Office.CommandBarButton", It doesn't work for
add button item
in "slide show" popup menu, I am very confused!

Please help me, Thanks
--
Best Regards
Steven
Steve Rindsberg
2006-09-25 15:46:54 UTC
Permalink
Post the code you use to add the button and also the code the button's supposed
to invoke.

You should also understand that your button will only work reliably on your own
computer and only when the PPT file containing the OnAction code is currently
open.

In short, this isn't really the way to add buttons to toolbars if you expect
them to work well.

Instead, you want to create an add-in.

Have a look here:
Creating and Installing Add-ins, Toolbars, Buttons
http://www.pptfaq.com/index.html#name_Creating_and_Installing_Add-ins-_Toolbars
-_Buttons_
Post by Steven
I write a macro and add a button item "Hello" in powerpoint's Standard
toolbar, and assign
onAction property(a function name), after i add it, why is it disable? I
don't click it!
but if I add the buttom in "slide show" popup menu, It works, I don't know
reason! I write it with macro!
If I write code with vb, then compile it, I define "
Dim WithEvents buttonHello As Office.CommandBarButton", It doesn't work for
add button item
in "slide show" popup menu, I am very confused!
Please help me, Thanks
--
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================
Steven
2006-09-26 09:20:20 UTC
Permalink
Thanks for answer! Code is as following!
'========================

Dim WithEvents buttonHello As Office.CommandBarButton

Private Sub IDTExtensibility2_OnConnection(ByVal Application As Object,
ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, ByVal AddInInst
As Object, custom() As Variant)
Dim objCommandBar As Office.CommandBar
Dim objCommandBarSlide As Office.CommandBar

Set objBar = oApp.CommandBars
For Each objCommandBar In objBar
If objCommandBar.Name = "Slide Show" And objCommandBar.Type = 2 Then
Set objCommandBarSlide = objCommandBar
Exit For
End If
Next

With objCommandBarSlide
Set buttonHello = .Controls.Add(Type:=msoControlButton)
With buttonHello
.FaceId = 10
.Style = msoButtonIconAndCaption
.Caption = "Hello"
.Enabled = True
.Visible = True
End With
End With

End Sub

Public Sub buttonHello_Click(ByVal Ctrl As Office.CommandBarButton,
CancelDefault As Boolean)
MsgBox "me click"
End Sub

'========================

I can see buttom Item "Hello" in slide show menu, but if I slide show and
right-click "slide show" menu, then click "Hello" button it, It is nothing
happen! I hope we can see Msgbox "me clikc", Can u tell me why I can't see
this msgbox? Thanks
--
Best Regards
Steven
Post by Steve Rindsberg
Post the code you use to add the button and also the code the button's supposed
to invoke.
You should also understand that your button will only work reliably on your own
computer and only when the PPT file containing the OnAction code is currently
open.
In short, this isn't really the way to add buttons to toolbars if you expect
them to work well.
Instead, you want to create an add-in.
Creating and Installing Add-ins, Toolbars, Buttons
http://www.pptfaq.com/index.html#name_Creating_and_Installing_Add-ins-_Toolbars
Post by Steve Rindsberg
-_Buttons_
Post by Steven
I write a macro and add a button item "Hello" in powerpoint's Standard
toolbar, and assign
onAction property(a function name), after i add it, why is it disable? I
don't click it!
but if I add the buttom in "slide show" popup menu, It works, I don't know
reason! I write it with macro!
If I write code with vb, then compile it, I define "
Dim WithEvents buttonHello As Office.CommandBarButton", It doesn't work for
add button item
in "slide show" popup menu, I am very confused!
Please help me, Thanks
--
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================
Steve Rindsberg
2006-09-27 04:11:53 UTC
Permalink
In your code that creates the button, in addition to .FaceId and the rest, you
need to set an .OnAction property to a string that identifies the subroutine
you want the button click to run.

.OnAction = "buttonHello_Click"
Post by Steven
Thanks for answer! Code is as following!
'========================
Dim WithEvents buttonHello As Office.CommandBarButton
Private Sub IDTExtensibility2_OnConnection(ByVal Application As Object,
ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, ByVal AddInInst
As Object, custom() As Variant)
Dim objCommandBar As Office.CommandBar
Dim objCommandBarSlide As Office.CommandBar
Set objBar = oApp.CommandBars
For Each objCommandBar In objBar
If objCommandBar.Name = "Slide Show" And objCommandBar.Type = 2 Then
Set objCommandBarSlide = objCommandBar
Exit For
End If
Next
With objCommandBarSlide
Set buttonHello = .Controls.Add(Type:=msoControlButton)
With buttonHello
.FaceId = 10
.Style = msoButtonIconAndCaption
.Caption = "Hello"
.Enabled = True
.Visible = True
End With
End With
End Sub
Public Sub buttonHello_Click(ByVal Ctrl As Office.CommandBarButton,
CancelDefault As Boolean)
MsgBox "me click"
End Sub
'========================
I can see buttom Item "Hello" in slide show menu, but if I slide show and
right-click "slide show" menu, then click "Hello" button it, It is nothing
happen! I hope we can see Msgbox "me clikc", Can u tell me why I can't see
this msgbox? Thanks
--
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================
Steven
2006-09-27 05:55:15 UTC
Permalink
Thanks for answer, I already add code
OnAction = "buttonHello_Click", It still does not work!

I modify OnAction = "Call buttonHello_Click(Nothing, False) or OnAction =
"buttonHello_Click(Nothing, False)", It does not work!
Nothing is happen!
but If I add this button in "Standard" toolbar, it works even if I have not
add OnAction code!

Can u help me find reason? Thanks
--
Best Regards
Steven
Post by Steve Rindsberg
In your code that creates the button, in addition to .FaceId and the rest, you
need to set an .OnAction property to a string that identifies the subroutine
you want the button click to run.
OnAction = "buttonHello_Click"
Post by Steven
Thanks for answer! Code is as following!
'========================
Dim WithEvents buttonHello As Office.CommandBarButton
Private Sub IDTExtensibility2_OnConnection(ByVal Application As Object,
ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, ByVal AddInInst
As Object, custom() As Variant)
Dim objCommandBar As Office.CommandBar
Dim objCommandBarSlide As Office.CommandBar
Set objBar = oApp.CommandBars
For Each objCommandBar In objBar
If objCommandBar.Name = "Slide Show" And objCommandBar.Type = 2 Then
Set objCommandBarSlide = objCommandBar
Exit For
End If
Next
With objCommandBarSlide
Set buttonHello = .Controls.Add(Type:=msoControlButton)
With buttonHello
.FaceId = 10
.Style = msoButtonIconAndCaption
.Caption = "Hello"
.Enabled = True
.Visible = True
End With
End With
End Sub
Public Sub buttonHello_Click(ByVal Ctrl As Office.CommandBarButton,
CancelDefault As Boolean)
MsgBox "me click"
End Sub
'========================
I can see buttom Item "Hello" in slide show menu, but if I slide show and
right-click "slide show" menu, then click "Hello" button it, It is nothing
happen! I hope we can see Msgbox "me clikc", Can u tell me why I can't see
this msgbox? Thanks
--
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================
Steve Rindsberg
2006-09-27 15:13:05 UTC
Permalink
Post by Steven
Thanks for answer, I already add code
OnAction = "buttonHello_Click", It still does not work!
Start by simplifying.
Post by Steven
Post by Steve Rindsberg
Post by Steven
Private Sub IDTExtensibility2_OnConnection(ByVal Application As Object,
ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, ByVal
AddInInst
It's not clear whether this is part of a COM addin or a PowerPoint file or
PowerPoint Addin.

Try rewriting the whole thing as a PPT macro or two, get that working, then
translate back to whatever you really need to do.
Post by Steven
I modify OnAction = "Call buttonHello_Click(Nothing, False) or OnAction =
"buttonHello_Click(Nothing, False)", It does not work!
Nothing is happen!
but If I add this button in "Standard" toolbar, it works even if I have not
add OnAction code!
Can u help me find reason? Thanks
--
Best Regards
Steven
Post by Steve Rindsberg
In your code that creates the button, in addition to .FaceId and the rest,
you
Post by Steve Rindsberg
need to set an .OnAction property to a string that identifies the
subroutine
Post by Steve Rindsberg
you want the button click to run.
OnAction = "buttonHello_Click"
Post by Steven
Thanks for answer! Code is as following!
'========================
Dim WithEvents buttonHello As Office.CommandBarButton
Private Sub IDTExtensibility2_OnConnection(ByVal Application As Object,
ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, ByVal
AddInInst
Post by Steve Rindsberg
Post by Steven
As Object, custom() As Variant)
Dim objCommandBar As Office.CommandBar
Dim objCommandBarSlide As Office.CommandBar
Set objBar = oApp.CommandBars
For Each objCommandBar In objBar
If objCommandBar.Name = "Slide Show" And objCommandBar.Type = 2
Then
Post by Steve Rindsberg
Post by Steven
Set objCommandBarSlide = objCommandBar
Exit For
End If
Next
With objCommandBarSlide
Set buttonHello = .Controls.Add(Type:=msoControlButton)
With buttonHello
.FaceId = 10
.Style = msoButtonIconAndCaption
.Caption = "Hello"
.Enabled = True
.Visible = True
End With
End With
End Sub
Public Sub buttonHello_Click(ByVal Ctrl As Office.CommandBarButton,
CancelDefault As Boolean)
MsgBox "me click"
End Sub
'========================
I can see buttom Item "Hello" in slide show menu, but if I slide show
and
Post by Steve Rindsberg
Post by Steven
right-click "slide show" menu, then click "Hello" button it, It is
nothing
Post by Steve Rindsberg
Post by Steven
happen! I hope we can see Msgbox "me clikc", Can u tell me why I can't
see
Post by Steve Rindsberg
Post by Steven
this msgbox? Thanks
--
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================
--
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================
Steven
2006-09-28 00:37:30 UTC
Permalink
It is a COM add-in! then we insert this add-in in powerpoint!
If I write macro in powerpoint, it works, but If I write this COM
add-in(translate to vb language), It don't works for this slide show menu's
button!
for this add-in other menu bar, toolbar, it works! I write it with VB!

Thanks
--
Best Regards
Steven
Post by Steve Rindsberg
Post by Steven
Thanks for answer, I already add code
OnAction = "buttonHello_Click", It still does not work!
Start by simplifying.
Post by Steven
Post by Steve Rindsberg
Post by Steven
Private Sub IDTExtensibility2_OnConnection(ByVal Application As Object,
ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, ByVal
AddInInst
It's not clear whether this is part of a COM addin or a PowerPoint file or
PowerPoint Addin.
Try rewriting the whole thing as a PPT macro or two, get that working, then
translate back to whatever you really need to do.
Post by Steven
I modify OnAction = "Call buttonHello_Click(Nothing, False) or OnAction =
"buttonHello_Click(Nothing, False)", It does not work!
Nothing is happen!
but If I add this button in "Standard" toolbar, it works even if I have not
add OnAction code!
Can u help me find reason? Thanks
--
Best Regards
Steven
Post by Steve Rindsberg
In your code that creates the button, in addition to .FaceId and the rest,
you
Post by Steve Rindsberg
need to set an .OnAction property to a string that identifies the
subroutine
Post by Steve Rindsberg
you want the button click to run.
OnAction = "buttonHello_Click"
Post by Steven
Thanks for answer! Code is as following!
'========================
Dim WithEvents buttonHello As Office.CommandBarButton
Private Sub IDTExtensibility2_OnConnection(ByVal Application As Object,
ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, ByVal
AddInInst
Post by Steve Rindsberg
Post by Steven
As Object, custom() As Variant)
Dim objCommandBar As Office.CommandBar
Dim objCommandBarSlide As Office.CommandBar
Set objBar = oApp.CommandBars
For Each objCommandBar In objBar
If objCommandBar.Name = "Slide Show" And objCommandBar.Type = 2
Then
Post by Steve Rindsberg
Post by Steven
Set objCommandBarSlide = objCommandBar
Exit For
End If
Next
With objCommandBarSlide
Set buttonHello = .Controls.Add(Type:=msoControlButton)
With buttonHello
.FaceId = 10
.Style = msoButtonIconAndCaption
.Caption = "Hello"
.Enabled = True
.Visible = True
End With
End With
End Sub
Public Sub buttonHello_Click(ByVal Ctrl As Office.CommandBarButton,
CancelDefault As Boolean)
MsgBox "me click"
End Sub
'========================
I can see buttom Item "Hello" in slide show menu, but if I slide show
and
Post by Steve Rindsberg
Post by Steven
right-click "slide show" menu, then click "Hello" button it, It is
nothing
Post by Steve Rindsberg
Post by Steven
happen! I hope we can see Msgbox "me clikc", Can u tell me why I can't
see
Post by Steve Rindsberg
Post by Steven
this msgbox? Thanks
--
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================
--
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================
Jim Carlock
2006-09-28 02:27:51 UTC
Permalink
Post by Steven
It is a COM add-in! then we insert this add-in in powerpoint!
If I write macro in powerpoint, it works, but If I write this COM
add-in(translate to vb language), It don't works for this slide show
menu's button!
for this add-in other menu bar, toolbar, it works! I write it with VB!
<snip code>
Private Sub IDTExtensibility2_OnConnection( _
ByVal Application As Object, _
ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, _
ByVal AddInInst As Object, _
custom() As Variant)
Dim objCommandBar As Office.CommandBar
Dim objCommandBarSlide As Office.CommandBar

Set objBar = oApp.CommandBars
</snip>

Where is objBar declared? I don't see a declaration for it anywhere.
Could that be a problem? Your file should have Option Explicit at
the top of it to help catch undeclared variables.
--
Jim Carlock
Post replies to the group.
Steven
2006-09-28 03:10:34 UTC
Permalink
I have define it! in class's top
'=====================
Implements IDTExtensibility2

Dim WithEvents oApp As PowerPoint.Application

Dim objBar As Office.CommandBars
--
Best Regards
Steven
Post by Jim Carlock
Post by Steven
It is a COM add-in! then we insert this add-in in powerpoint!
If I write macro in powerpoint, it works, but If I write this COM
add-in(translate to vb language), It don't works for this slide show
menu's button!
for this add-in other menu bar, toolbar, it works! I write it with VB!
<snip code>
Private Sub IDTExtensibility2_OnConnection( _
ByVal Application As Object, _
ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, _
ByVal AddInInst As Object, _
custom() As Variant)
Dim objCommandBar As Office.CommandBar
Dim objCommandBarSlide As Office.CommandBar
Set objBar = oApp.CommandBars
</snip>
Where is objBar declared? I don't see a declaration for it anywhere.
Could that be a problem? Your file should have Option Explicit at
the top of it to help catch undeclared variables.
--
Jim Carlock
Post replies to the group.
Steven
2006-09-28 03:12:16 UTC
Permalink
I have define it! in class's top
'=====================
Option Explicit

Implements IDTExtensibility2

Dim WithEvents oApp As PowerPoint.Application
Dim objBar As Office.CommandBars
--
Best Regards
Steven
Post by Jim Carlock
Post by Steven
It is a COM add-in! then we insert this add-in in powerpoint!
If I write macro in powerpoint, it works, but If I write this COM
add-in(translate to vb language), It don't works for this slide show
menu's button!
for this add-in other menu bar, toolbar, it works! I write it with VB!
<snip code>
Private Sub IDTExtensibility2_OnConnection( _
ByVal Application As Object, _
ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, _
ByVal AddInInst As Object, _
custom() As Variant)
Dim objCommandBar As Office.CommandBar
Dim objCommandBarSlide As Office.CommandBar
Set objBar = oApp.CommandBars
</snip>
Where is objBar declared? I don't see a declaration for it anywhere.
Could that be a problem? Your file should have Option Explicit at
the top of it to help catch undeclared variables.
--
Jim Carlock
Post replies to the group.
Loading...