Pasting an Excel range using VBA to PPT - pasted positions change

我的梦境 提交于 2019-12-13 20:17:57

问题


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:


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.



来源:https://stackoverflow.com/questions/47045422/pasting-an-excel-range-using-vba-to-ppt-pasted-positions-change

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!