使用VBA到PPT粘贴Excel范围 - 粘贴的位置会发生变化

时间:2017-10-31 22:28:18

标签: excel vba excel-vba position

我正在使用VBA从Excel复制范围并将其粘贴到PowerPoint幻灯片中。我添加了顶部,左侧和宽度坐标来定位幻灯片。我粘贴的范围不会改变 - 发生的事情是左侧位置发生变化的某些天。今天,它是最高位置。我没有改变坐标。我已经用Google搜索了这个问题而没有找到解决方案。代码如下。

'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 个答案:

答案 0 :(得分:0)

我在Excel中遇到了同样的问题,让我发疯,而我能确定的最好的是缩放不是100%或更改缩放级别导致.top和.left中的位置自动更改。即使在工作表和工作簿之间进行更改也会导致职位转变。