Im looking for a way to take ranges in excel turn them into linked pictures in a power point presentation. I currently got most of it down, by combining a few diffrent codes i found, except i cannot get the pictures to link to the ranges, which sadly is a must.
My current code:
Sub PasteMultipleSlides_testing_link()
'PURPOSE: Copy Excel Ranges and Paste them into the Active PowerPoint presentation slides
'SOURCE: www.TheSpreadsheetGuru.com
Dim myPresentation As Object
Dim mySlide As Object
Dim PowerPointApp As Object
Dim shp As Object
Dim MySlideArray As Variant
Dim MyRangeArray As Variant
Dim x As Long
'Create an Instance of PowerPoint
On Error Resume Next
'Is PowerPoint already opened?
Set PowerPointApp = GetObject(class:="PowerPoint.Application")
'Clear the error between errors
Err.Clear
'If PowerPoint is not already open then Exit
If PowerPointApp Is Nothing Then
MsgBox "PowerPoint Presentation is not open, aborting."
Exit Sub
End If
'Handle if the PowerPoint Application is not found
If Err.Number = 429 Then
MsgBox "PowerPoint could not be found, aborting."
Exit Sub
End If
On Error GoTo 0
'Make PowerPoint Visible and Active
PowerPointApp.ActiveWindow.Panes(2).Activate
'Create a New Presentation
Set myPresentation = PowerPointApp.ActivePresentation
'List of PPT Slides to Paste to
MySlideArray = Array(4, 6, 8)
'List of Excel Ranges to Copy from
MyRangeArray = Array(Sheet1.Range("C4:F11"), Sheet3.Range("C4:F11"), Sheet5.Range("C4:F11"))
'Loop through Array data
For x = LBound(MySlideArray) To UBound(MySlideArray)
'Copy Excel Range
MyRangeArray(x).Copy
'Paste to PowerPoint
Set shp = myPresentation.Slides(MySlideArray(x)).Shapes.PasteSpecial(DataType:=2)
'Position object
With myPresentation
shp.LockAspectRatio = msoFalse
shp.Left = 133
shp.Top = 177
shp.Height = 200
shp.Width = 300
shp.LockAspectRatio = msoTrue
End With
Next x
'Transfer Complete
Application.CutCopyMode = False
ThisWorkbook.Activate
End Sub
Theres some extra code in there, which is to adjust the size, positioning, and slides for the objects, which is needed as each range needs to go into a specific slide, in a specific location.
Any way to get the pictures to also become linked to the ranges, such that if i change the excel range, the picture changes aswell? I have managed to get this working by copying it manually, but i cannot get VBA to do it automaticly, and sadly i cannot record a macro where i take action between excel and powerpoint. Note that ideally, it should work without me having to start by selecting the object i wanna link (saw alot of guides that suggested this method), as i need to create a larger number of linked pictures.
thanks in advance!
My current code:
Sub PasteMultipleSlides_testing_link()
'PURPOSE: Copy Excel Ranges and Paste them into the Active PowerPoint presentation slides
'SOURCE: www.TheSpreadsheetGuru.com
Dim myPresentation As Object
Dim mySlide As Object
Dim PowerPointApp As Object
Dim shp As Object
Dim MySlideArray As Variant
Dim MyRangeArray As Variant
Dim x As Long
'Create an Instance of PowerPoint
On Error Resume Next
'Is PowerPoint already opened?
Set PowerPointApp = GetObject(class:="PowerPoint.Application")
'Clear the error between errors
Err.Clear
'If PowerPoint is not already open then Exit
If PowerPointApp Is Nothing Then
MsgBox "PowerPoint Presentation is not open, aborting."
Exit Sub
End If
'Handle if the PowerPoint Application is not found
If Err.Number = 429 Then
MsgBox "PowerPoint could not be found, aborting."
Exit Sub
End If
On Error GoTo 0
'Make PowerPoint Visible and Active
PowerPointApp.ActiveWindow.Panes(2).Activate
'Create a New Presentation
Set myPresentation = PowerPointApp.ActivePresentation
'List of PPT Slides to Paste to
MySlideArray = Array(4, 6, 8)
'List of Excel Ranges to Copy from
MyRangeArray = Array(Sheet1.Range("C4:F11"), Sheet3.Range("C4:F11"), Sheet5.Range("C4:F11"))
'Loop through Array data
For x = LBound(MySlideArray) To UBound(MySlideArray)
'Copy Excel Range
MyRangeArray(x).Copy
'Paste to PowerPoint
Set shp = myPresentation.Slides(MySlideArray(x)).Shapes.PasteSpecial(DataType:=2)
'Position object
With myPresentation
shp.LockAspectRatio = msoFalse
shp.Left = 133
shp.Top = 177
shp.Height = 200
shp.Width = 300
shp.LockAspectRatio = msoTrue
End With
Next x
'Transfer Complete
Application.CutCopyMode = False
ThisWorkbook.Activate
End Sub
Theres some extra code in there, which is to adjust the size, positioning, and slides for the objects, which is needed as each range needs to go into a specific slide, in a specific location.
Any way to get the pictures to also become linked to the ranges, such that if i change the excel range, the picture changes aswell? I have managed to get this working by copying it manually, but i cannot get VBA to do it automaticly, and sadly i cannot record a macro where i take action between excel and powerpoint. Note that ideally, it should work without me having to start by selecting the object i wanna link (saw alot of guides that suggested this method), as i need to create a larger number of linked pictures.
thanks in advance!