Hi,
I wrote this code to send from my current page in xls the content into a new ppt presentation.
I have 2 pbm I can't resolve:
1) the created image is ok when the code runs on my laptop. But when it runs on a PC (with probably a different screen definition), the right side of the image disapear.
2) I would like the macro to add the charts to the same presentation. But it creats each time I launch it a new ppt presentation.
Anyone can help?
Thank you
-------------------------------------------------
Sub MoveActiveChartToPPT()
' Dim strMsg As String
Dim appPPT As New PowerPoint.Application
Dim pptActive As PowerPoint.Presentation
Dim slideNew As Slide
Dim Title
Dim Comment
Dim strcomment
Dim shpcomment
Dim strtitle
Dim slidecount As Integer
Dim shpChart As PowerPoint.Shape, shpTitle As PowerPoint.Shape
' Dim i%
On Error GoTo GestionErreurs
Title = InputBox("Please enter a Title:")
Comment = InputBox("Please enter a Comment:")
With appPPT
.Visible = True
Set pptActive = .Presentations.Add
.Activate
slidecount = pptActive.Slides.Count
Set slideNew = pptActive.Slides.Add(slidecount + 1, ppLayoutBlank)
appPPT.ActiveWindow.View.GotoSlide slideNew.SlideIndex
End With
With pptActive
.Slides(1).Shapes.AddLabel(Orientation:=msoTextOrientationHorizontal, _
Left:=40, Top:=30, Width:=60, Height:=100).TextFrame.TextRange.Text = Title
End With
With pptActive
Set shpTitle = slideNew.Shapes(1)
End With
strtitle = Title
With shpTitle
.Top = 10
.Left = pptActive.PageSetup.SlideWidth / 4
.Width = pptActive.PageSetup.SlideWidth - pptActive.PageSetup.SlideWidth / 4
With .TextFrame.TextRange
.Text = strtitle
.ParagraphFormat.Alignment = ppAlignLeft
With .Font
.NameAscii = "Arial"
.Size = 26
.Bold = msoTrue
.BaselineOffset = 0
.Color.SchemeColor = ppTitle
End With
End With
End With
With pptActive
.Slides(1).Shapes.AddLabel(Orientation:=msoTextOrientationHorizontal, _
Left:=40, Top:=60, Width:=60, Height:=300).TextFrame.TextRange.Text = Comment
End With
With pptActive
Set shpcomment = slideNew.Shapes(2)
End With
strcomment = Comment
With shpcomment
.Top = 45
.Left = 8
.Width = pptActive.PageSetup.SlideWidth - 8
With .TextFrame.TextRange
.Text = strcomment
.ParagraphFormat.Alignment = ppAlignLeft
With .Font
.NameAscii = "Arial"
.Size = 16
.Bold = msoTrue
.BaselineOffset = 0
.Color.RGB = RGB(12, 80, 255)
End With
End With
End With
Range("c1:aa44").Select
' Copy the range as a picture
Selection.CopyPicture Appearance:=xlScreen, _
Format:=xlPicture
' Paste the range
slideNew.Shapes.Paste.Select
' Align the pasted range
appPPT.ActiveWindow.Selection.ShapeRange.Align msoAlignCenters, True
appPPT.ActiveWindow.Selection.ShapeRange.Align msoAlignMiddles, True
Set shpChart = slideNew.Shapes(slideNew.Shapes.Count)
With shpChart
.Left = pptActive.PageSetup.SlideWidth * 0.03
.Top = 85
.Width = pptActive.PageSetup.SlideWidth * 0.95
End With
' Clean up
Set slideNew = Nothing
Set appPPT = Nothing
Set pptActive = Nothing
Range("a1").Select
Exit Sub
GestionErreurs:
Resume Next
End Sub
I wrote this code to send from my current page in xls the content into a new ppt presentation.
I have 2 pbm I can't resolve:
1) the created image is ok when the code runs on my laptop. But when it runs on a PC (with probably a different screen definition), the right side of the image disapear.
2) I would like the macro to add the charts to the same presentation. But it creats each time I launch it a new ppt presentation.
Anyone can help?
Thank you
-------------------------------------------------
Sub MoveActiveChartToPPT()
' Dim strMsg As String
Dim appPPT As New PowerPoint.Application
Dim pptActive As PowerPoint.Presentation
Dim slideNew As Slide
Dim Title
Dim Comment
Dim strcomment
Dim shpcomment
Dim strtitle
Dim slidecount As Integer
Dim shpChart As PowerPoint.Shape, shpTitle As PowerPoint.Shape
' Dim i%
On Error GoTo GestionErreurs
Title = InputBox("Please enter a Title:")
Comment = InputBox("Please enter a Comment:")
With appPPT
.Visible = True
Set pptActive = .Presentations.Add
.Activate
slidecount = pptActive.Slides.Count
Set slideNew = pptActive.Slides.Add(slidecount + 1, ppLayoutBlank)
appPPT.ActiveWindow.View.GotoSlide slideNew.SlideIndex
End With
With pptActive
.Slides(1).Shapes.AddLabel(Orientation:=msoTextOrientationHorizontal, _
Left:=40, Top:=30, Width:=60, Height:=100).TextFrame.TextRange.Text = Title
End With
With pptActive
Set shpTitle = slideNew.Shapes(1)
End With
strtitle = Title
With shpTitle
.Top = 10
.Left = pptActive.PageSetup.SlideWidth / 4
.Width = pptActive.PageSetup.SlideWidth - pptActive.PageSetup.SlideWidth / 4
With .TextFrame.TextRange
.Text = strtitle
.ParagraphFormat.Alignment = ppAlignLeft
With .Font
.NameAscii = "Arial"
.Size = 26
.Bold = msoTrue
.BaselineOffset = 0
.Color.SchemeColor = ppTitle
End With
End With
End With
With pptActive
.Slides(1).Shapes.AddLabel(Orientation:=msoTextOrientationHorizontal, _
Left:=40, Top:=60, Width:=60, Height:=300).TextFrame.TextRange.Text = Comment
End With
With pptActive
Set shpcomment = slideNew.Shapes(2)
End With
strcomment = Comment
With shpcomment
.Top = 45
.Left = 8
.Width = pptActive.PageSetup.SlideWidth - 8
With .TextFrame.TextRange
.Text = strcomment
.ParagraphFormat.Alignment = ppAlignLeft
With .Font
.NameAscii = "Arial"
.Size = 16
.Bold = msoTrue
.BaselineOffset = 0
.Color.RGB = RGB(12, 80, 255)
End With
End With
End With
Range("c1:aa44").Select
' Copy the range as a picture
Selection.CopyPicture Appearance:=xlScreen, _
Format:=xlPicture
' Paste the range
slideNew.Shapes.Paste.Select
' Align the pasted range
appPPT.ActiveWindow.Selection.ShapeRange.Align msoAlignCenters, True
appPPT.ActiveWindow.Selection.ShapeRange.Align msoAlignMiddles, True
Set shpChart = slideNew.Shapes(slideNew.Shapes.Count)
With shpChart
.Left = pptActive.PageSetup.SlideWidth * 0.03
.Top = 85
.Width = pptActive.PageSetup.SlideWidth * 0.95
End With
' Clean up
Set slideNew = Nothing
Set appPPT = Nothing
Set pptActive = Nothing
Range("a1").Select
Exit Sub
GestionErreurs:
Resume Next
End Sub