Commandbutton.onAction

riniheijnen

New Member
Joined
Feb 8, 2012
Messages
6
I have an excelsheet with a certain range "realusedrange" that has to be pasted in a Powerpint-slide. Because I want to give the user the possibility to make complete the range I made a commandbutton on the excelsheet. When the user presses this button another macro should be started where the pasting happens.

realusedrange.Copy
Cells(lastrow + 2, 3).Select

With Selection
ActiveSheet.buttons.Add(ActiveCell.Left, ActiveCell.Top, 120,60).Select
Selection.OnAction = "PERSONAL.XLSB!macro_powerpoint_slide()"
Selection.Characters.Text = "Powerpoint" & vbCrLf & "Presentatie"
With Selection.Characters(Start:=1, Length:=23).Font
.Name = "Calibri"
.FontStyle = "Standaard"
.Size = 16
End With
End With

Sub macro_powerpoint_slide()

Dim pptApp As PowerPoint.Application
Dim pptPrs As PowerPoint.Presentation
Dim pptSld As PowerPoint.Slide
Dim pptshp As PowerPoint.Shape

Set pptApp = CreateObject("Powerpoint.application")

pptApp.Visible = True

Set pptPrs = pptApp.Presentations.Open("C:\VVVierpolders\automation\Templates\TV-sponsors template." & "potx")
Set pptSld = pptPrs.Slides(1)
Set pptshp = pptSld.Shapes(1)

'plakken excel-tabel in powerpoint slide
pptSld.Shapes.PasteSpecial(ppPasteOLEObject).Select

End Sub

When I run the code I'll get an error

"unable to set the onaction property of the button class"

When I put the text of the second macro at the end of the first macro it works ok for me.
I guess I have to pass "realusedrange"tot the macro "macro_powerpoint_slide()" but I don't know how.
Anyone has any suggesions?
Code:
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top