Excel Shapes to Powerpoint (Naming)

jon7187

New Member
Joined
Oct 5, 2009
Messages
10
The current code below is a subroutine for an Excel to PowerPoint framework I am developing.

This works fine but I was just wondering if there was a way to either get the object number of the newly pasted object or to be able to label the object for manipulation(Instead of using the Object Number parameter).

For reference a typical line in the controller looks something like this:

Code:
Call CopyGroupPasteBitmap("NamedGroupOfCharts", 1, 2, , 73)

Which copies the NamedGroupOfCharts, pastes them to slide 1 and is the 2nd object on the slide with a height of 73 points.


Thanks in Advance,
Jon Lorenzini

Code:
Sub CopyGroupPasteBitmap(GroupName As String, SlideNumber As Integer, ObjectNumber As Integer, Optional Left As Variant, Optional Top As Variant, Optional Width As Variant, Optional Height As Variant)

'Makes the Correct Slide Active
Set PPT_Slide = PPT_File.Slides(SlideNumber)
'Copys Chart

ActiveSheet.Shapes.Range(Array(GroupName)).Select
Selection.Copy
'Pastes as Bitmap
With PPT_Slide
.Shapes.PasteSpecial DataType:=ppPasteBitmap, DisplayAsIcon:=msoTrue
End With

'Adjusts Height Width Left and Top per variables passed
    With PPT_Slide.Shapes(ObjectNumber)
        'Prevents Distortion of Images
        .LockAspectRatio = msoTrue
        
        'If there isn't a width variable then it sizes the width of Object to fit on PPT Slide
        If IsMissing(Width) = True Then
        .Width = (PPT_File.PageSetup.SlideWidth) - 20
            Else
            .Width = Width
        End If
        
        'If there isn't a height variable, it checks if it will go past the footer. If it is larger then it resizes it, otherwise it leaves it alone
         If IsMissing(Height) = True Then
            If PPT_Slide.Shapes(ObjectNumber).Height > (PPT_File.PageSetup.SlideHeight - Top - Footer) Then
                .Height = (PPT_File.PageSetup.SlideHeight) - Top - Footer
            Else
            End If
            Else
            .Height = Height
        End If
        
        'If there isn't a left variable then it centers it on the PPT Slide
        If IsMissing(Left) = True Then
            .Left = (PPT_File.PageSetup.SlideWidth - .Width) / 2
            Else
            .Left = Left
        End If
        
        'If there isn't a top variable then it centers it on the PPT Slide
        If IsMissing(Top) = True Then
            .Top = (PPT_File.PageSetup.SlideHeight - .Height) / 2
            Else
            .Top = Top
        End If
    End With
End Sub
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
To clarify somewhere in here should name the shape to be referenced in the with second immediately after.

Code:
With PPT_Slide
.Shapes.PasteSpecial DataType:=ppPasteBitmap, DisplayAsIcon:=msoTrue
End With

'Adjusts Height Width Left and Top per variables passed
    With PPT_Slide.Shapes(ObjectNumber)
        'Prevents Distortion of Images
        .LockAspectRatio = msoTrue
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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