首页 文章

使用VBA-Excel在Powerpoint幻灯片中粘贴多个形状

提问于
浏览
0

我创建了一个Excel宏来处理excel中的一些数据(每次迭代两个值),将数据引入一个范围(每次迭代两个单元格),将复制/粘贴范围作为图像(形状)引入到给定的PowerPoint幻灯片中给出顶部/左侧值 .

宏按预期工作,但随着粘贴形状的数量增加,跳过随机形状的机会也会增加(没有错误消息) . 我已经尝试了几次代码并且从未经历过相同的结果:有时缺少两三个形状,有时八个,有时没有...

我在每次粘贴后使用DoEvents并且(以防它有帮助)一个Sleep函数定义为:“Public Declare Sub Sleep Lib”kernel32“(ByVal dwMilliseconds As Long)”

我有办法将所有粘贴的图像组合成Excel中每张幻灯片的一个大图像吗?有没有人有任何其他建议?

以下代码取自宏,为简单起见,我省略了其余部分 . 此代码放在两个嵌套的For循环中 .

'Variable calculations
LastRow = .Cells(.rows.Count, .Range("statusCol").Column).End(xlUp).Row
LastCol = .Cells(61, .Columns.Count).End(xlToLeft).Column
Set rng = .Range(.Cells(61, .Range("statusCol").Column), .Cells(LastRow, LastCol))

rng.Copy

If ExcelApp.ClipboardFormats(1) Then    ' Check clipboard contents

    mySlide.Shapes.PasteSpecial DataType:=2  
    DoEvents

    ' Changing the pasted cell's position and size
    Set myShape = mySlide.Shapes(mySlide.Shapes.Count)
    With myShape
        .LockAspectRatio = msoTrue
        .Left = TableLeft
        .Top = TableTop
        .Height = 20 * rng.rows.Count                  
    End With
End If

1 回答

  • 0

    我想到了一个简单的解决方案,显然已经完成了这个诀窍:

    oldCount = mySlide.Shapes.Count
    ' Pasting and verifying that it was done successfully
    While (mySlide.Shapes.Count <= oldCount)
        mySlide.Shapes.PasteSpecial DataType:=2  
        DoEvents
    Wend
    

    到目前为止,仅检查形状的数量是否已增加已解决了该问题 .

相关问题