Pasting an Excel range using VBA to PPT - pasted p

2019-08-16 16:17发布

I am using VBA to copy a range from Excel and paste this to a PowerPoint slide. I add the top, left, and width coordinates to position the slide. The range I am pasting does not change - what is happening is some days the left position changes. Today, it was the top position. I am not changing the coordinates. I've Googled this issue and not have found a solution. Code is below.

'Oct17
'Open a slide to the Presentation
  Set mySlide = myPresentation.Slides(10)

'Copy Range from Excel
   Set rng = ThisWorkbook.Sheets("Oct17").Range("A1:N68")
   Set rng2 = ThisWorkbook.Sheets("Oct17").Range("L73:N73")

'Copy Excel Range
  rng.Copy

'Paste to PowerPoint and position
PowerPointApp.WindowState = 2
mySlide.Shapes.PasteSpecial DataType:=0  '2 = ppPasteEnhancedMetafile  0 = ppPasteDefault
Set myShape = mySlide.Shapes(mySlide.Shapes.Count)

'Set position:
myShape.Left = 20        '15 / 0 / 20
myShape.Top = 70         '91
myShape.Width = 675
'myShape.Height = 400

'Copy Excel Range
  rng2.Copy

'Paste to PowerPoint and position
PowerPointApp.WindowState = 2
mySlide.Shapes.PasteSpecial DataType:=2  '2 = ppPasteEnhancedMetafile  0 = ppPasteDefault
Set myShape = mySlide.Shapes(mySlide.Shapes.Count)

'Set position:
myShape.Left = 494
myShape.Top = 527
myShape.Width = 300
'Make PowerPoint Visible and Active
'PowerPointApp.Visible = msoTrue
'PowerPointApp.Activate

'Clear The Clipboard
Application.CutCopyMode = False
Application.Wait (Now + TimeValue("00:00:01"))

1条回答
Juvenile、少年°
2楼-- · 2019-08-16 17:07

I was having the same issue in Excel driving me mad and the best I could determine was that having zoom not at 100% or changing zoom levels caused the position in .top and .left to change unprompted. Even changing between worksheets and workbooks caused the positions to shift.

查看更多
登录 后发表回答