Why is it disable for add button item

S

Steven

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
 
S

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.

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_
 
S

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
 
S

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"
 
S

Steven

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
 
S

Steve Rindsberg

Thanks for answer, I already add code
OnAction = "buttonHello_Click", It still does not work!

Start by simplifying.
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.
 
S

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!

Thanks
 
J

Jim Carlock

Steven said:
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.
 
S

Steven

I have define it! in class's top
'=====================
Implements IDTExtensibility2

Dim WithEvents oApp As PowerPoint.Application

Dim objBar As Office.CommandBars
 
S

Steven

I have define it! in class's top
'=====================
Option Explicit

Implements IDTExtensibility2

Dim WithEvents oApp As PowerPoint.Application
Dim objBar As Office.CommandBars
 

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