ulster0709
New Member
- Joined
- Aug 14, 2016
- Messages
- 13
Hi Experts,
I have just learned <acronym title="visual basic for applications" style="border-width: 0px 0px 1px; border-bottom-style: dotted; border-bottom-color: rgb(0, 0, 0); cursor: help; color: rgb(51, 51, 51); background-color: rgb(250, 250, 250);">vba</acronym> few months ago and I got a problem that I havent been able to solve, could you help me or give me some advice please.
I have an excel vba code that works fine for copying and pasting a chart from Excel into powerpoint, but it doesnt paste it into the placeholder, I am just wondering how should the code be amended in order to paste it into a placeholder, see the code below
Option Explicit
Sub Marcro3()
Dim PPT As Object
Set PPT = CreateObject("PowerPoint.Application")
PPT.Visible = True
PPT.Presentations.Open Filename:="path"
copy_chart "report", 3, "Chart 1" ' Name of the sheet to copy graph and slide number the graph is to be pasted in
'PPT.Save
'PPT.Close
End Sub
Public Function copy_chart(sheet, slide, name)
Dim PPApp As Object
Dim PPPres As Object
Dim PPSlide As Object
Dim nPlcHolder As Long
Set PPApp = CreateObject("Powerpoint.Application")
Set PPApp = GetObject(, "Powerpoint.Application")
Set PPPres = PPApp.ActivePresentation
PPApp.ActiveWindow.View.GotoSlide (slide)
Worksheets(sheet).Activate
ActiveSheet.ChartObjects(name).Chart.CopyPicture _
Appearance:=xlScreen, Size:=xlScreen, Format:=xlPicture
Set PPSlide = PPPres.slides(PPApp.ActiveWindow.Selection.SlideRange.SlideIndex)
With PPSlide
' paste and select the chart picture
.Shapes.Paste.Select
End With
' Clean up
Set PPSlide = Nothing
Set PPPres = Nothing
Set PPApp = Nothing
End Function
Below is more information about the problem
Excel
Spreadsheet name: Report generator
Spreadsheet location: (Already activate)
Worksheet: Summary
Chart name: Chart 1
Powerpoint
Powerpoint name: report
powerpoint location: (already activate)
Slide: P.3
Placeholder position: the one of the left, I am not sure whether there is a name for the placeholders on powerpoint (there are two placeholders on P.3, one on the right, the other one on the left)
Thank you!
I have just learned <acronym title="visual basic for applications" style="border-width: 0px 0px 1px; border-bottom-style: dotted; border-bottom-color: rgb(0, 0, 0); cursor: help; color: rgb(51, 51, 51); background-color: rgb(250, 250, 250);">vba</acronym> few months ago and I got a problem that I havent been able to solve, could you help me or give me some advice please.
I have an excel vba code that works fine for copying and pasting a chart from Excel into powerpoint, but it doesnt paste it into the placeholder, I am just wondering how should the code be amended in order to paste it into a placeholder, see the code below
Option Explicit
Sub Marcro3()
Dim PPT As Object
Set PPT = CreateObject("PowerPoint.Application")
PPT.Visible = True
PPT.Presentations.Open Filename:="path"
copy_chart "report", 3, "Chart 1" ' Name of the sheet to copy graph and slide number the graph is to be pasted in
'PPT.Save
'PPT.Close
End Sub
Public Function copy_chart(sheet, slide, name)
Dim PPApp As Object
Dim PPPres As Object
Dim PPSlide As Object
Dim nPlcHolder As Long
Set PPApp = CreateObject("Powerpoint.Application")
Set PPApp = GetObject(, "Powerpoint.Application")
Set PPPres = PPApp.ActivePresentation
PPApp.ActiveWindow.View.GotoSlide (slide)
Worksheets(sheet).Activate
ActiveSheet.ChartObjects(name).Chart.CopyPicture _
Appearance:=xlScreen, Size:=xlScreen, Format:=xlPicture
Set PPSlide = PPPres.slides(PPApp.ActiveWindow.Selection.SlideRange.SlideIndex)
With PPSlide
' paste and select the chart picture
.Shapes.Paste.Select
End With
' Clean up
Set PPSlide = Nothing
Set PPPres = Nothing
Set PPApp = Nothing
End Function
Below is more information about the problem
Excel
Spreadsheet name: Report generator
Spreadsheet location: (Already activate)
Worksheet: Summary
Chart name: Chart 1
Powerpoint
Powerpoint name: report
powerpoint location: (already activate)
Slide: P.3
Placeholder position: the one of the left, I am not sure whether there is a name for the placeholders on powerpoint (there are two placeholders on P.3, one on the right, the other one on the left)
Thank you!