PDA

View Full Version : Name pictures when pasting into PowerPoint - VBA



iowa_70
10-16-2009, 04:55 AM
Hi, I'm copying a range of cells from Excel and then pasting them into PowerPoint 2000. When I paste the pictures they all have the default name "Picture 1, 2,.....etc". How do I rename them something else when pasting?

Thanks!


...
iForced = 0
MaxNumForced = Sheets("Objects").Range("A1")

For iForced = 1 To MaxNumForced

'Copy range as a picture
Sheets("Objects").Select
Range("Forced_" & iForced).Select
Selection.CopyPicture Appearance:=xlScreen, Format:=xlPicture


' Paste the range
PPSlide.Shapes.Paste.Select

' Align the pasted range
PPApp.ActiveWindow.Selection.ShapeRange.Align msoAlignCenters, True
PPApp.ActiveWindow.Selection.ShapeRange.Align msoAlignMiddles, True

Next iForced
....

Cosmo
10-16-2009, 07:04 AM
Hi, I'm copying a range of cells from Excel and then pasting them into PowerPoint 2000. When I paste the pictures they all have the default name "Picture 1, 2,.....etc". How do I rename them something else when pasting?

Thanks!


...
iForced = 0
MaxNumForced = Sheets("Objects").Range("A1")

For iForced = 1 To MaxNumForced

'Copy range as a picture
Sheets("Objects").Select
Range("Forced_" & iForced).Select
Selection.CopyPicture Appearance:=xlScreen, Format:=xlPicture


' Paste the range
PPSlide.Shapes.Paste.Select

' Align the pasted range
PPApp.ActiveWindow.Selection.ShapeRange.Align msoAlignCenters, True
PPApp.ActiveWindow.Selection.ShapeRange.Align msoAlignMiddles, True

Next iForced
....


Use the returned shaperange value from your paste command:


iForced = 0
MaxNumForced = Sheets("Objects").Range("A1")

For iForced = 1 To MaxNumForced

'Copy range as a picture
Sheets("Objects").Select
Range("Forced_" & iForced).Select
Selection.CopyPicture Appearance:=xlScreen, Format:=xlPicture


' Paste the range

dim pastedShapeRange as shapeRange
set pastedShapeRange = PPSlide.Shapes.Paste
with pastedShapeRange
' name your range here
.Align msoAlignCenters, True
.Align msoAlignMiddles, True
end with

Next iForced
....

This also allows you to use the actual shaperange in your next few steps, instead of the selection.