Putting a command button to run a macro

User avatar
chamdan
3StarLounger
Posts: 372
Joined: 17 Dec 2013, 00:07

Putting a command button to run a macro

Post by chamdan »

Hi,

Is there a way to put a command button in PowerPoint to execute a macro? I am using MS Office 2010.

The reason for that is that I have a macro that will update the Presentation based on an excel workbook, which contains 2 tables on the same worksheet.
I have select the range K1 to contain the range for the first Table e.g. : A1:I17 and then in L1 I have the second range, which !8:I33

Now the reason for doing this is in case the user increase or decrease the range of those table the powerpoint will pickup always the correct range and then process it then upload it into the powerPoint slide.

Looking forward to hearing from you.

Chuck

User avatar
HansV
Administrator
Posts: 74177
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Putting a command button to run a macro

Post by HansV »

Option 1:

Activate the Developer tab of the ribbon.
Click on the Command Button button in the Controls group.
Either click on the slide where you want the command button, or drag a rectangle.
Double-click the new button.
This takes you to the Visual Basic Editor and create an On Click event procedure for the command button.
You can call your macro from there:

Code: Select all

Private Sub CommandButton1_Click()
    Call MyMacro
End Sub
When you run the presentation, you can click the button.

Option 2:
Activate the Insert tab of the ribbon.
Click on Shapes, then select the last shape in the Action Buttons section, named Action Button: Custom.
Click on the slide or drag a rectangle.
When you release the mouse button, the Action Settings dialog comes up.
Select 'Run Macro' in the Mouse Click tab, then select the macro you want to run.
Finally click OK.
S0696.png
You do not have the required permissions to view the files attached to this post.
Regards,
Hans

User avatar
chamdan
3StarLounger
Posts: 372
Joined: 17 Dec 2013, 00:07

Re: Putting a command button to run a macro

Post by chamdan »

Thank you Hnas I will follow your instructions and will let you know.

Regards,

Chuck

User avatar
chamdan
3StarLounger
Posts: 372
Joined: 17 Dec 2013, 00:07

Re: Putting a command button to run a macro

Post by chamdan »

Hans,

I tried it but the button does not react the same way as in Excel??? Check the image of the buuton after creation, By the way I selected option 1 you described but after inserting the macro as you mentioned I am not able to execute the macro the button seems to be still in edit mode.
Snap2.jpg
instead of:
Snap3.jpg
Although I finished entering the macro for the button click event as mentioned:

Code: Select all

Private Sub CommandButton1_Click()
XLPresentation
End Sub
Chuck
You do not have the required permissions to view the files attached to this post.

User avatar
Rudi
gamma jay
Posts: 25393
Joined: 17 Mar 2010, 17:33
Location: Cape Town

Re: Putting a command button to run a macro

Post by Rudi »

Hi Chuck,

You can only execute the macro from the button when you are in Slide Show mode. The button will always be in "Edit" mode unless you actually show the presentation.
Regards,
Rudi

If your absence does not affect them, your presence didn't matter.

User avatar
chamdan
3StarLounger
Posts: 372
Joined: 17 Dec 2013, 00:07

Re: Putting a command button to run a macro

Post by chamdan »

Rudi,

Thanks for the tip. So I cannot execute the amendment of the sides since it is in slide show. My objective is to update the slides prior running the show.

Can this be done?

Chuck

User avatar
HansV
Administrator
Posts: 74177
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Putting a command button to run a macro

Post by HansV »

If you want to update the slides before the presentation, you don't use a button on a slide. Press Alt+F8 to activate the Macros dialog...
Regards,
Hans

User avatar
chamdan
3StarLounger
Posts: 372
Joined: 17 Dec 2013, 00:07

Re: Putting a command button to run a macro

Post by chamdan »

:thankyou: Hans,

I was trying to avoid letting the user to use the Alt-F8 but :groan: Well that's what PowerPoint offers only.

Well thanks again for your amazing support.

You really deserve a :cheers:

Chuck

PJ_in_FL
5StarLounger
Posts: 969
Joined: 21 Jan 2011, 16:51
Location: Florida

Re: Putting a command button to run a macro

Post by PJ_in_FL »

While in Edit mode click Alt-F8 which opens the Macro dialog box. Select the macro to run from the list and press the Run button. The Macro dialog can also be accessed via the Macros button on the Developer tab.

You may want to use the Step Into button first to walk through the code to be sure it runs correctly in Edit mode.

(OK, the above was suggested by Hans before I got this written)

Alternate ending to the story:
Use another PowerPoint set up to auto-show as a front-end. Save the front-end PP file as a .PPS file (via the Save As dialog), then have the macro open the PowerPoint file to update, perform the same updates from the Excel table, then save and close the modified file.

Once the modifications are complete, another button on the front-end PP file can then open the modified file in Slide-show mode.
PJ in (usually sunny) FL