excel - 粘贴幻灯片时出错: The specified data type is unavailable

标签 excel vba runtime-error powerpoint

在 PowerPoint 中将幻灯片粘贴到以下行时遇到以下错误:

PPApp.ActiveWindow.View.PasteSpecial ppPasteOLEObject, msoFalse

Run-time error -2147188160 (80048240):View (unknown member) : Invalid request. The specified data type is Unavailable

我已经多次运行此代码,并且之前运行良好。

此外,一旦对象/图表正在复制;我正在切换到 PowerPoint 看看是否可以粘贴。 我可以粘贴所有选项(作为图片、作为嵌入图像等)。

这是完整的代码,直到我收到错误,因为它没有出现在评论部分

这是代码:直到出现错误的行

 Sub export_to_ppt()
 Set objExcel = CreateObject("Excel.Application")
 'Keep the Importing master sheet address here:
  Set objWorkbook = objExcel.Workbooks.Open("d:\Documents and   Settings \Export to   ppt.xlsm")

'Keep all the worksheets which you want to import from here:
Path = "D:\Office Documents\2013\ Latest Xcel\" 
Filename = Dir(Path & "*.xlsm")
Do While Filename <> ""
Workbooks.Open Filename:=Path & Filename, ReadOnly:=True
Dim sht As Workbooks

 Set Sheet = Workbooks(Filename).Sheets("Issues Concern")
 Sheet.Copy After:=ThisWorkbook.Sheets(1)
 Set Sheet = Workbooks(Filename).Sheets("Key Initiatives Update")
 Sheet.Copy After:=ThisWorkbook.Sheets(1)
 Set Sheet = Workbooks(Filename).Sheets("Solution Update")
 Sheet.Copy After:=ThisWorkbook.Sheets(1)
 Set Sheet = Workbooks(Filename).Sheets("Overall Practice Status")
 Sheet.Copy After:=ThisWorkbook.Sheets(1)
 Set Sheet = Workbooks(Filename).Sheets("Practice Financials")
 Sheet.Copy After:=ThisWorkbook.Sheets(1)
 Workbooks(Filename).Close
 Filename = Dir()
 Loop
Dim PPApp           As PowerPoint.Application
Dim PPPres          As PowerPoint.Presentation
Dim PPSlide         As PowerPoint.Slide
Dim SlideCount      As Integer
Dim shptbl          As Table
Dim oShape          As PowerPoint.Shape

Dim SelectRange As Range
Dim SelectCell As Range


 Set PPApp = CreateObject("PowerPoint.Application")
 PPApp.Visible = msoTrue
'opening an existing presentation
 Filename = "D:\Office Documents\Presentation1.pptx"
 Set PPPres = PPApp.Presentations.Open(Filename) 
 Dim s As String
 Dim i As Integer
 i = 2
  Line3:
MsgBox (ActiveSheet.Name)

If ActiveSheet.Name Like ("*Solution Update*") Then
GoTo Line1
ElseIf ActiveSheet.Name Like ("*Key Initatives Update*") Then
GoTo Line4
ElseIf ActiveSheet.Name Like ("*Issues Concern*") Then
GoTo Line13

End If



Set PPSlide = PPPres.Slides.Add(SlideCount + 1, ppLayoutTitleOnly)

PPSlide.Shapes(1).TextFrame.TextRange.Text = "Practice Financials - " &  Sheets(i).Range("AH1").Value & "  "

'PPSlide.Shapes(1).TextFrame.TextRange.Text = Sheets(1).Range("B1").Value

'format header
With PPSlide.Shapes(1).TextFrame.TextRange.Characters
    .Font.Size = 24
    .Font.Name = "Arial Heading"
    '.Font.Color = vbBlue
End With



Range("A1:K7").Select

Selection.Copy
PPApp.ActiveWindow.View.GotoSlide PPSlide.SlideIndex ' activate the slide no
'PPApp.Activate
 PPApp.ActiveWindow.View.PasteSpecial ppPasteOLEObject, msoFalse ' paste using pastespecial method
 'PPApp.ActiveWindow.View.PasteSpecial ppPasteEnhancedMetafile
 'PPApp.ActiveWindow.View.PasteSpecial (ppPasteMetafilePicture) 

最佳答案

我遇到了同样的问题,它发生在我尝试从 Excel 导出到 PowerPoint 时,没有 PowerPoint 引用,并将其用作对象。棘手的是,有时它有效,有时则无效。因此,经过一些测试后,我发现这取决于 PowerPoint View 的状态,是显示缩略图还是正常的幻灯片 View 。

要修复此问题,请在粘贴之前将 ViewType 设置为正常。

PPAP.ActiveWindow.ViewType = ppViewNormal

PPAP.ActiveWindow.ViewType = 9

PPAP 代表 Power Point 应用程序对象。

关于excel - 粘贴幻灯片时出错: The specified data type is unavailable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20139130/

相关文章:

vba - 使用图表格式化

java - 在静态 block Eclipse-java 中断言

java - 尝试对字符串进行标记化时出现 NumberFormatException

r - 如何将摘要()输出从 R 复制到 Excel

vba - 如何手动保存 VBA 监视或通过代码添加它们?

sql - Excel VBA - 如何从 SQL 查询中填充数组

java - 错误: cannot find symbol: class FileNotFoundException

excel - 如何使用多个分隔符拆分字符串并在vba excel中加入部分?

excel - 使用 VBA 关闭 Excel 应用程序

java - Apache POI 和 EXCEL