PowerPoint VBA

编程入门 行业动态 更新时间:2024-10-09 15:23:57
本文介绍了PowerPoint VBA-将形状复制到幻灯片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已经开发了Powerpoint VBA函数,并向其传递了Shape和Slide对象。

I have developed a Powerpoint VBA function to which I pass a Shape and Slide object.

该函数在其中查找带有文本LOGO的形状,如果找到,它将用我传递给该函数的形状替换该形状。

The function finds for a shape with text LOGO inside it, if it finds, it replaces that shape with the shape I passed to the function.

该功能在Office 2013上可以正常使用,但在Office 2016上则不能。

Function works perfectly on office 2013 but not on Office 2016.

有人可以为此建议一个解决方法吗?

Can anybody please suggest a work around for this?

Public Sub AddLogo_ONE(shLogo As Shape, oSlide As PowerPoint.Slide) Dim sh As Shape For Each sh In oSlide.Shapes If sh.HasTextFrame Then If UCase(sh.TextFrame2.TextRange.Text) = "LOGO" Then oSlide.Select DoEvents: DoEvents shLogo.Copy With oSlide.Shapes.Paste .LockAspectRatio = msoFalse .Left = sh.Left .Top = sh.Top - ((.Height - sh.Height) / 2) .AlternativeText = "LogoMacro" sh.TextFrame2.TextRange.Font.Fill.ForeColor.RGB = RGB(255, 255, 255) End With Exit For End If End If Next End Sub

以下是我在Powerpoint 2016上收到的错误消息:

Below is the error message I get on Powerpoint 2016:

推荐答案

这是VBA / Clipboard / WinOS的。我亲自花费了数小时试图为此设计一个巧妙的解决方案,甚至在继续粘贴操作之前都使用WinAPI检查并等待剪贴板中的PowerPoint类型的内容可用,而无济于事。

That's the dreaded machine dependent timing issue with VBA/Clipboard/WinOS. I have personally spent hours trying to devise a clever solution for this, even using WinAPIs to check and wait for a PowerPoint type of content to be available in the clipboard before proceeding with a Paste operation, all to no avail.

我发现唯一可行的解​​决方案是延迟VBA的速度。讨厌的解决方法,因为它仍然取决于计算机。这是我使用的功能:

The only solution I have found that works is to slow VBA down with a delay. Nasty workaround as it's still machine dependent. This is the function I use:

Public Sub Delay(Seconds As Single, Optional DoAppEvents As Boolean) Dim TimeNow As Long TimeNow = Timer Do While Timer < TimeNow + Seconds If DoAppEvents = True Then DoEvents Loop End Sub

如果您按以下方式调用它(减少从1秒钟到失败的时间,然后再次加倍!),它应该可以解决您的问题:

If you call this as follows (reduce the time from 1 second until it fails and then double it again!), it should solve your issue:

shLogo.Copy Delay 1, True With oSlide.Shapes.Paste

更多推荐

PowerPoint VBA

本文发布于:2023-10-31 10:15:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1545783.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:PowerPoint   VBA

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!