使用VBA将Excel范围粘贴到PPT-粘贴位置更改 [英] Pasting an Excel range using VBA to PPT - pasted positions change

查看:120
本文介绍了使用VBA将Excel范围粘贴到PPT-粘贴位置更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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"))

推荐答案

我在Excel中遇到了同样的问题,这使我发疯了,我能确定的最好办法是,变焦未达到100%或更改了变焦水平会导致该位置.top和.left可以无提示地进行更改.即使在工作表和工作簿之间进行更改也会导致位置发生变化.

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.

这篇关于使用VBA将Excel范围粘贴到PPT-粘贴位置更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆