【问题标题】:Pasting multiple shapes in a Powerpoint Slide using VBA-Excel使用 VBA-Excel 在 Powerpoint 幻灯片中粘贴多个形状
【发布时间】:2018-12-15 01:04:12
【问题描述】:

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

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

我在每次粘贴之后都使用 DoEvents,并且(以防万一)一个睡眠函数定义为:“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

【问题讨论】:

标签: excel vba powerpoint shapes


【解决方案1】:

我想到了一个足够简单的解决方案,显然已经成功了:

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

到目前为止,只需检查形状的数量是否增加就可以解决问题。

【讨论】:

    猜你喜欢
    • 2014-10-15
    • 2020-05-18
    • 1970-01-01
    • 1970-01-01
    • 2022-12-23
    • 1970-01-01
    • 1970-01-01
    • 2017-11-06
    • 1970-01-01
    相关资源
    最近更新 更多