错误:“指定的数据类型不可用"在 PowerPoint 中将形状粘贴为 PNG 格式时 [英] Error: "The specified data type is unavailable" When pasting Shapes as PNG format in PowerPoint
问题描述
我需要编写一个宏来将 PPT 演示文稿中的所有分组图表(形状、箭头和文本)转换为 PNG.(我正在使用一些电子学习软件转换 PPT,但图表最终已损坏;我需要它们是 PNG,因为增强的元文件也存在问题).
I need to write a macro to convert all grouped diagrams (shapes, arrows and text) in a PPT presentation to PNGs. (I am converting the PPTs using some eLearning software and the diagrams end up corrupt; and I need them to be PNGs because enhanced metafiles also present issues).
我一直在使用一些稍微修改过的代码,该代码来自一个将图片(增强的元文件)转换为 PNG 的宏.我所做的只是将 msoPicture 更改为 msoGroup:
I've been using some slightly modified code from a macro that converts Pictures (enhanced meta files) to PNGs. All I did was change msoPicture to msoGroup:
Sub ConvertAllPicsToPNG()
Dim oSl As Slide
Dim oSh As Shape
For Each oSl In ActivePresentation.Slides
For Each oSh In oSl.Shapes
' modify the following depending on what you want to
' convert
Select Case oSh.Type
Case msoGroup
ConvertPicToPNG oSh
Case Else
End Select
Next
Next
End Sub
Sub ConvertPicToPNG(ByRef oSh As Shape)
Dim oNewSh As Shape
Dim oSl As Slide
Set oSl = oSh.Parent
oSh.Copy
Set oNewSh = oSl.Shapes.PasteSpecial(ppPastePNG)(1)
With oNewSh
.Left = oSh.Left
.Top = oSh.Top
Do
.ZOrder (msoSendBackward)
Loop Until .ZOrderPosition = .ZOrderPosition
End With
oSh.Delete
End Sub
我在线上收到错误Shapes (unknown member)"
I get the error "Shapes (unknown member)" on the line
Set oNewSh = oSl.Shapes.PasteSpecial(ppPastePNG)(1)
我怀疑我在使用 VBA 的对象参考模型时遇到了问题,因为研究告诉我 GroupItems 和 GroupShapes,但我无法理解.
I suspect I'm having problems with VBA's Object Reference Model, as research has told me of GroupItems and GroupShapes, but I can't fathom it.
推荐答案
我在 PPT 2010 中收到此错误:形状(未知成员):无效请求.剪贴板为空或包含可能无法粘贴到此处的数据."
I get this error in PPT 2010: "Shapes (unknown member) : Invalid request. Clipboard is empty or contains data which may not be pasted here."
当您缩小或使用选择窗格时,我们都注意到有Shape 125":
We both notice there is "Shape 125" when you zoom out or use the Selection Pane:
经过多次反复试验(我认为嵌套可能是一个问题,并尝试取消嵌套 - 成功,但错误仍然发生)我注意到它们每个都有 的高度0
.如果我将其更改为任何正值,则成功!
After a lot of trial and error (I thought the nesting might be a problem, and tried to un-nest them -- successfully, but the error still happened) I noticed that each of them had a height of 0
. If I changed that to any positive value, success!
所以这是修复 - 调用一个新函数以确保形状的高度 > 0:
So here is the fix -- call a new function to make sure shapes have height > 0:
For Each oSh In oSl.Shapes
' modify the following depending on what you want to
' convert
Select Case oSh.Type
Case msoGroup
'Ensure each grouped shape has h/w of at least "1"
FixShape oSh
ConvertPicToPNG oSh
Case Else
功能如下:
Function FixShape(ByRef oSh As Shape)
Dim s As Shape
'## Iterate the GroupItems collection and ensure minimum height/width
' for converion to png/jpg/etc.
For Each s In oSh.GroupItems
If s.Height = 0 Then s.Height = 1
If s.Width = 0 Then s.Width = 1
'Recursive
If s.Type = msoGroup Then
Set s = FixShape(s)
End If
Next
Set FixShape = oSh
End Function
这是将形状转换为 PNG 的最终输出:
Here is the final output which converts the shapes to PNG:
此错误的根本原因
似乎您无法将高度/宽度为 0 的形状粘贴为 PNG 格式(尽管您可以将它们粘贴为形状).这似乎是有意的限制,但不幸的是错误信息含糊不清.
It seems you are not able to paste shapes with height/width of 0, as PNG format (although you can paste them as Shapes). This seems to be an intentional limitation, but unfortunately the error message is ambiguous.
此错误的解决方案
在尝试粘贴为图像格式(PNG、JPG 等)之前,请确保形状的最小尺寸为 1x1
Ensure that shapes have minimum dimensions of 1x1 before trying to paste as an image format (PNG, JPG, etc.)
虽然您可以通过删除有问题的形状来解决问题,但这应该会对您有所帮助,这样您就不必搜索那些脱离窗格的形状或在将来再次尝试解决此问题.
While you were able to resolve the problem by deleting the offending shape, this should help you so that you don't have to search for those off-pane shapes or try to troubleshoot this again in the future.
这篇关于错误:“指定的数据类型不可用"在 PowerPoint 中将形状粘贴为 PNG 格式时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!