View Full Version : Command to open a user Form

08-22-2007, 01:08 PM
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:

<<< ----- Begin Code Snippet --- >>>

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

Exit Sub ' so it doesn't go on to run the errorhandler code

'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"
End Sub

<<< ----- End Code Snippet --- >>>

Thanks for any assistance.

08-22-2007, 03:03 PM
Clarification... the toolbar button works as long as the form I am opening resides in the toolbar presentation. I want to be able to call code in the current presentation (not the toolbar presentation) using the user form.

For example I set up a simple msgbox test on module two of my presentation (geekin.ppt). geekin.ppt has the toolbar and button created using the code from my post above. The toolbar code is in a presentation called toolbar.ppt which is saved as toolbar.ppa then added as an addin to geekin.ppt.

I need to access the vba code on geekin.ppt either by calling a form on geekin.ppt or using the form in toolbar.ppt and calling code in geekin.ppt. I am new to powerpoint vba development so please forgive me if I am missing something.

Thanks again for any assistance.

John Wilson
08-23-2007, 04:52 AM
Works for me
but I would suggest
load frmCBR

Things to check
Macro security is it set higher than medium
Macro Security > trusted publishers is "trust all installed addins " ticked
In Tools > Addins does the add in show and is it ticked?

08-23-2007, 07:22 AM
Thank you for your reply. I don't believe I am having any issues with the toolbar itself. What I mean is the toolbar appears in my presentation by using the Tools / Addins feature. I am able to browse to the "ppa" file and successfully add the toolbar. The toolbar appears and button 1 calls the "Sub Button1()" code detailed below. In fact the msgBox displays then the form code is called. When the frmCBR.show code is called I get a run time error. I have trouble shooted the issue to the point where I feel the issue is that the toolbar code is only able to reference and/or call objects which are part of the toobar presentation??? (used strictly to create the toolbar - toolbar.ppa). The objects and code I need to access are in geekin.ppt. Again, since I am not familiar with powerpoint VBA development I may be missing something. I am open to any solution which would allow me to provide an accessible way for my user(s) to provide some user defined values and an interface to support a submit on geekin.ppt. I was under the impression that a userform and a button would be a logical choice. I can run the userform manually from within geekin.ppt visual basic environment and it works great... I simply can't seem to find a way to call the form from the normal presentation view. I am open to any other suggestions if this is not a good choice but I am sure there MUST be a path for accomplishing this. I would be happy to respond with any additional information which might be helpfull. Thanks again for any assistance.

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"
End Sub

08-23-2007, 08:55 AM
I feel like I am beginning to display signs of schizophrenia responding to myself but wanted to update the thread as my discovery process continues and because I still have not arrived at the final solution ... :banghead:

Customizing the toolbars and/or menus on my local copy of powerpoint to run a macro which calls my form works great. Now the issue is that this customization does not persist when I send the file to another client machine.

When viewed from a client machine the macro(s) are still present but the toolbar and/or menu customization(s) which call the macro disappears. If the solution is to use an add in then I am back to my prior issue which is the fact that the add in does not seem to be aware of the form or macros in my geekin.ppt presentation.


08-24-2007, 09:14 AM
After some research it appears that menu customizations do not persist to other machines because the configuration is saved to a pcb file on the local machine. I DO NOT want to get into the business of replacing pcb files on machines consuming this app. I will be distributing this solution to a very large sales force. This is why I am committed to finding a simple UI for launching my user form and why I want to stay away from updating files on other machines.

As a developer, I must admit that I am perplexed over the possiblility there may be no practicle way to provide a button or menu item which stays with the saved ppt file and allows users to simply launch a user form. :dunno

John Wilson
08-25-2007, 02:06 PM
Do you want the code / form to run during a show or in edit mode? Maybe I'm missing the point but during a show you can run code from an action setting or from a control button (both will travel with the file) Add In will never travel with the file they "live" on the computer theyre installed on (moving the pcb won't help")

08-27-2007, 06:59 AM
Since the ppt file opens initially in edit / design mode I would rather lauch the user form from there. Not to mention if I use a slide with a control on it, the slide will need to be deleted before the presentation is finalized and ready for delivery to our customer(s). That being said, I do appreciate your suggestion and that may be what I end up doing. I also may consider instructing the sales reps to use the Macro menu (Alt + F8) to run the macro manually. I'm sure you can appreciate why I'm hesitant to follow that path.

Anyone have any experience using the Auto Open macro to launch things when opened? I would be curios what kind of issues come up when the ppt is being used in a large user base. I could see where security settings etc. could cause some support issues?

Thanks for the reponse(s) and assistance...

John Wilson
08-27-2007, 07:46 AM
If you want the form to open in edit view it really needs to be part of the addin. Is that a possibility?

John Wilson
08-27-2007, 07:49 AM
Also you might want to look at "add a macro to a right click menu"

08-27-2007, 08:02 AM
Thanks John.
Certainly, I could include a form as part of the addin. In fact I've successfully tested opening a form from a button which was part of the addin. The issue I was having with that approach was I did not seem to have access to objects in the currently open ppt. For instance, calling code on the current ppt as opposed to the ppt saved as ppa which when compiled became to addin. Also, wouldn't I still have the issue with portability to other client machines? Ie: The addin not showing up in the ppt file when copied from one machine to another.

Ideally, I could use an addin which would remain with the file when distributed to other machines. The addin would be a toolbar button or other UI button which when clicked would either open a form on the current ppt file or open a form which resides in the addin codebase but would have access to code on the current ppt file.

Please feel free to correct me if my thinking is off :think:

John Wilson
08-27-2007, 08:25 AM
However you send the addin it will need to be installed on the client machine. We have a way of creating a self installing add in but the problem with macro security will still cause problems. There is no way of changing the settings via code (thank goodness). If you want to email me an example of what youre trying to do maybe I'll understand better. needs to be soon though as I'm away from tomorrow

john AT technologytrish.co.uk