【发布时间】:2014-04-24 03:27:25
【问题描述】:
您好,这是对这张票的跟进:How to resolve Missing Powerpoint 15 Object Library Error
我开发了一个宏,可以在 Excel 2010 中将某些内容从 excel 导出到 powerpoint。当我尝试部署到使用 Office 2010 的人时遇到了问题。根据 SO 的建议,我将引用更改为后期绑定以避免版本依赖性。现在可以在 Office 2010 上打开并运行宏,但用户仍会看到错误消息:“加载 DLL 时出现问题”。当我点击参考资料时,它说缺少 15 个 Powerpoint VBA。如果我取消选中此项并选中 14,它将运行,但似乎 2010 年的某个人每次运行宏时都必须这样做。关于如何进行的任何建议?我尝试添加以下内容来解决问题
1:修复引用的代码
Sub RemoveMissingReferences()
Dim Intrefcount As Integer
With ThisWorkbook.VBProject.references
For Intrefcount = 1 To .Count
If Left(.Item(Intrefcount).Description, 7) = "Missing" Then
.Remove .Item(Intrefcount)
End If
Next Intrefcount
End With
End Sub
2:从excel导出到PPT的实际宏
Sub CopyDataToPPTBrandPers()
Const ppLayouttitleonly = 11
Const ppPasteEnhancedMetafile = 2
Dim objWorkSheet As Worksheet
Dim objRange As Range
Dim objPPT, objslide, objPresentation, shapePPTOne As Object
Dim intLocation, intHeight, inLayout, intRefCount As Integer
Dim strRange As String
Dim boolRefExists As Boolean
Application.ScreenUpdating = False
boolRefExists = False
With ThisWorkbook.VBProject.references
For intRefCount = 1 To .Count
If .Item(intRefCount).Description = _
"Microsoft PowerPoint 14.0 Object Library" Then
boolRefExists = True
End If
Next intRefCount
End With
Set objPPT = CreateObject("PowerPoint.Application")
objPPT.Visible = True
inLayout = 1
strRange = "p19:y48" '<- here
intHeight = 430
Set objPresentation = objPPT.Presentations.Add
Set objslide = objPresentation.Slides.Add(1, inLayout)
objslide.Layout = ppLayouttitleonly
With objslide.Shapes.Title
With .TextFrame.TextRange
.Text = "Reebok - " & Sheets("Brand Personality").Cells(3, 2)
.Words.Font.Bold = msoTrue
.Font.Color = RGB(255, 255, 255)
End With
.Fill.Visible = msoTrue
.Fill.Solid
.Fill.ForeColor.RGB = RGB(192, 0, 0) '160, 157, 117)
.Height = 50
End With
Set objRange = Sheets("Brand Personality").Range(strRange)
objRange.Copy
Set shapePPTOne = objslide.Shapes.PasteSpecial(DataType:=ppPasteEnhancedMetafile, _
Link:=msoFalse)
DoEvents
If boolRefExists = True Then
shapePPTOne.Left = 100
shapePPTOne.Top = 100
shapePPTOne.Height = intHeight
Else
shapePPTOne(1).Left = 220
shapePPTOne(1).Top = 100
shapePPTOne(1).Height = intHeight
End If
Set shapePPTOne = Nothing
'Set shapePPTTwo = Nothing
Set objRange = Nothing
Set objPPT = Nothing
Set objPresentation = Nothing
Set objslide = Nothing
Application.CutCopyMode = False
Application.ScreenUpdating = True
MsgBox "Update Complete"
End Sub
【问题讨论】:
-
请注意,修复引用的 #1 代码在左侧命令中超时。我不知道为什么
-
如果您已经迁移到
Late Bind,那么只需删除任何Reference并保存.xlsm文件。Late Binding根本不需要任何参考。还有msoTrue和msoFalse是PPt变量,所以需要分别改成-1和0。然后尝试再次扫描您的代码,我可能会错过其他变量。 -
您的声明没有按照您的预期进行:Dim objPPT, objslide, objPresentation, shapePPTOne As Object 创建 shapePPTOne 作为 Object 变量,其余作为 Variants。同样: Dim intLocation, intHeight, inLayout, intRefCount As Integer 将 intRefCount 作为整数提供给您,其余的是变体。在这种情况下,它可能无关紧要,但有时会导致晦涩的错误和奇怪的结果。最好正确声明变量。
标签: excel excel-2010 powerpoint vba