粘贴幻灯片时出错:指定的数据类型不可用 [英] Error when pasting slide: The specified data type is unavailable

查看:201
本文介绍了粘贴幻灯片时出错:指定的数据类型不可用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在PowerPoint中的以下行中粘贴幻灯片时出现以下错误:

I am getting following error while pasting a slide in PowerPoint in the following line:

PPApp.ActiveWindow.View.PasteSpecial ppPasteOLEObject, msoFalse

运行时错误-2147188160(80048240):视图(未知成员):无效的请求.指定的数据类型不可用

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

我已经多次运行了此代码,之前运行得很好.

I have run this code multiple times and it was running fine before.

此外,一旦对象/图表被复制;我切换到PowerPoint,看看是否可以粘贴.我可以粘贴所有选项(例如图片,嵌入图像等).

Also, once the object/chart is copying; I am switching to PowerPoint to see if I can paste. I can paste with all the options (As picture, As Embedded Image, etc.).

这是完整的代码,直到我收到错误提示为止,因为它没有出现在注释部分

Here is the full code till I am getting error as it was not coming in comment section

代码如下:直到出现错误的那一行为止

Here is the code : Till the line where I get error

 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) 

推荐答案

在上面我的评论中,这对我有用.假设您的 sheet1 看起来像这样

Further to my comments above, this works for me. Let's say your sheet1 looks like this

将此代码粘贴到模块中.

Paste this code in a module.

Option Explicit

Sub Sample()
    Dim PPApp           As PowerPoint.Application
    Dim PPPres          As PowerPoint.Presentation
    Dim PPSlide         As PowerPoint.Slide
    Dim SlideCount      As Long

    Dim ws As Worksheet
    Dim rng As Range

    Dim Filename As String

    Set ws = ThisWorkbook.Sheets("Sheet1")

    Set rng = ws.Range("A1:K7")

    Set PPApp = CreateObject("PowerPoint.Application")
    PPApp.Visible = msoTrue
    'opening an existing presentation
    Filename = "C:\Presentation1.pptx"
    Set PPPres = PPApp.Presentations.Open(Filename)

    SlideCount = PPPres.Slides.count

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

    With PPSlide.Shapes(1).TextFrame.TextRange
        .Text = "Practice Financials - " & _
                ws.Range("AH1").Value & "  "

        With .Characters.Font
            .Size = 24
            .Name = "Arial Heading"
        End With
    End With

    rng.Copy
    DoEvents

    PPSlide.Shapes.PasteSpecial DataType:=ppPasteOLEObject, Link:=msoFalse
End Sub

输出

这篇关于粘贴幻灯片时出错:指定的数据类型不可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆