在Excel VBA中定位形状

时间:2018-07-03 07:29:05

标签: object runtime-error powerpoint positioning shapes

我正在使用excel VBA,并尝试复制一些excel范围并将其复制到PPT幻灯片。我使用数组将粘贴复制到相应的幻灯片。但是,当代码到达以下行:“ shp.Left = 60”时,它想在其中放置形状,则会出现错误。 “运行时错误91:对象变量或未设置块”。谁能帮忙解决这个错误?谢谢!

VBA代码:

'要粘贴到的PPT幻灯片列表   MySlideArray = Array(4,7,9,12,15,15,18,20,23,25,28,30,32,34,36,38,40,42,44)

'要复制的Excel范围列表 MyRangeArray = Array(Sheet13。[C6:N29],Sheet13。[C36:N59],Sheet15。[C6:N27],Sheet15。[C34:N54],Sheet12。[C6:N27],Sheet12。[C34:N54 ],Sheet17。[C6:N27],Sheet17。[C34:N54],Sheet18。[C6:N27],Sheet18。[C34:N54],Sheet19。[C6:N27],Sheet19。[C34:N54], Sheet20。[C6:N27],Sheet20。[C34:N54],Sheet21。[C6:N27],Sheet21。[C34:N54],Sheet22。[C6:N27],Sheet22。[C34:N54])

'遍历数组数据   对于x = LBound(MySlideArray)到UBound(MySlideArray)     '复制Excel范围         MyRangeArray(x).Copy

'Paste to PowerPoint and position
  On Error Resume Next
    Set shp = myPresentation.Slides(MySlideArray(x)).Shapes.PasteSpecial(DataType:=2) 'Excel 2007-2010
    Set shp = PowerPointApp.ActiveWindow.Selection.ShapeRange 'Excel 2013
  On Error GoTo 0

'Position Object
'strangely need to have a existing pasted shape on the PPT slide already, else get error object variable not set
  With shp
    shp.Left = 60
    shp.Top = 110
    shp.Width = 600

  End With

0 个答案:

没有答案