PDA

View Full Version : VBA Code to Insert Picture from Excel To PP w. specific dimensions/size



ASIM
09-18-2014, 04:42 AM
Hi all.

I am currently looking into how I can speed up my work flow of creating reports.

Currently I am copying data from excel to powerpoint (Enhanced Meta File), deleting the old picture from last month, resizing the new picture and making sure it is in the correct position.
I am doing this sequence for many different excel ouputs.

I would like a way so that when I copy a selected area from excel and go to power point and select the picture I would like to replace then:
1) Delete the selected picture
2) Paste the Excel data as an enhanced meta file (or some picture format) at the same position and size as the just deleted picture from step 1.

Is this possible? Or do some of you have any other suggestions to improve my work flow on this specific task.

I am on Office 2010

John Wilson
09-20-2014, 09:12 AM
Are you able to use code? You could fairly easily use code to switch and resize the picture assuming you know how to add and run it.

Example (might need work- Select but not delete the picture to be changed)


Sub picInsert()
Dim opic As Shape
Dim opicOrig As Shape
Dim sngL As Single
Dim sngT As Single
Dim sngW As Single
Dim sngH As Single
Set opicOrig = ActiveWindow.Selection.ShapeRange(1)
sngT = opicOrig.Top
sngL = opicOrig.Left
sngW = opicOrig.Width
sngH = opicOrig.Height
Set opic = opicOrig.Parent.Shapes.Paste(1)
opicOrig.Delete
opic.LockAspectRatio = False
opic.Left = sngL
opic.Top = sngT
opic.Width = sngW
opic.Height = sngH
End Sub

Does the picture to be pasted exist as a discrete file? If so try right click > change Picture.