I have some functionality which is being driven from a user form which works well. I need to be able to provide an intuitive way for the user to launch the form within powerpoint. My first approach was to create a button on a new toolbar then add it as an “Addin”. Problem I am experiencing is that the code for showing the form comes up with a run time error “Object required”
The code for opening the form is very simply “frmCBR.Show” (Below is full example)
I am saving the presentation with the toolbar code with a ppa extension then using the toolbar addin option.
Does the form itself need to reside in the presentation which has the command button syntax? I will continue to troubleshoot. Thought I’d post the question in case anyone has a solution.
Below is the code I am experimenting with which I took from a successful Google search for the toolbar creation:
Sub Auto_Open()
Dim oToolbar As CommandBar
Dim oButton As CommandBarButton
Dim MyToolbar As String
' Give the toolbar a name
MyToolbar = "Kewl Tools"
On Error Resume Next
' so that it doesn't stop on the next line if the toolbar's already there
' Create the toolbar; PowerPoint will error if it already exists
Set oToolbar = CommandBars.Add(Name:=MyToolbar, _
Position:=msoBarLeft, Temporary:=True)
If Err.Number <> 0 Then
' The toolbar's already there, so we have nothing to do
Exit Sub
End If
On Error GoTo ErrorHandler
' Now add a button to the new toolbar
Set oButton = oToolbar.Controls.Add(Type:=msoControlButton)
' And set some of the button's properties
With oButton
.DescriptionText = "This is my first button"
'Tooltip text when mouse if placed over button
.Caption = "CBR"
'Text if Text in Icon is chosen
.OnAction = "Button1"
'Runs the Sub Button1() code when clicked
.Style = msoButtonIcon
' Button displays as icon, not text or both
.FaceId = 1952
'52 is my favorite pig;
' chooses icon #52 from the available Office icons
End With
' Repeat the above for as many more buttons as you need to add
' Be sure to change the .OnAction property at least for each new button
' You can set the toolbar position and visibility here if you like
' By default, it'll be visible when created
oToolbar.Top = 150
oToolbar.Left = 150
oToolbar.Visible = True
NormalExit:
Exit Sub ' so it doesn't go on to run the errorhandler code
ErrorHandler:
'Just in case there is an error
MsgBox Err.Number & vbCrLf & Err.Description
Resume NormalExit:
End Sub
Sub Button1()
' This code will run when you click Button 1 added above
' Add a similar subroutine for each additional button you create on the toolbar
MsgBox "CBR New code - frmCBR show"
frmCBR.Show
End Sub
Thanks for any assistance.