2017-02-09 5 views
2

Ich verwende Late Binding, um Charts und Range von Excel nach PowerPoint zu kopieren.Fehler beim Kopieren von Excel-Bereich und PasteSpecial in PowerPoint-Folie (mit Late Binding)

ich die folgende Fehlermeldung erhalten:

enter image description here

An der dieser Codezeile:

Set myShape = ppSlide.Shapes.PasteSpecial(ppPasteEnhancedMetafile, msoFalse) 

Hinweis: Ich bin mit dem Range.Copy und Shapes.PasteSpecial als ppPasteEnhancedMetafile da nach einer viel Versuch und Irrtum gibt es die beste Auflösung in PowerPoint.

Hinweis # 2: Mit diesem PasteSpecial als ppPasteEnhancedMetafile gut für mich gearbeitet, als ich mit frühen Bindung. Ich musste aufgrund der Tatsache, dass Benutzer Office 2010, Office 2013 und Office 2016 ausführen (und ich möchte nicht, dass sie mit dem VB Project Ref. Zur PowerPoint-Bibliothek spielen), zu Late Binding wechseln.

My-Code

Option Explicit 

Public Sub UpdatePowerPoint(PowerPointFile) 

Dim ppProgram       As Object 
Dim ppPres        As Object 
Dim CurOpenPresentation     As Object 
Dim ppSlide        As Object  
Dim myShape        As Object 
Dim SlideNum       As Integer 
Dim StageStat       As String 

On Error Resume Next 
Set ppProgram = GetObject(, "PowerPoint.Application") 
On Error GoTo 0 

If ppProgram Is Nothing Then 
    Set ppProgram = CreateObject("PowerPoint.Application") 
Else 
    If ppProgram.Presentations.Count > 0 Then 
     For Each CurOpenPresentation In ppProgram.Presentations ' loop through all open presnetations (check Full Name: Path and name) 

      Dim CleanFullName As String * 1024 
      CleanFullName = Replace(CurOpenPresentation.FullName, "%20", " ") ' replace Sharepoint characters %20 with Space (" ") 

      Dim comStr As String * 1024 
      comStr = CStr(PowerPointFile) 

      If StrComp(comStr, CleanFullName, vbTextCompare) = 0 Then 
       Set ppPres = CurOpenPresentation 
       Exit For 
      End If 
     Next CurOpenPresentation 
    End If 
End If 

If ppPres Is Nothing Then ' if One-Pager presentation was not found from all open presentations 
    Set ppPres = ppProgram.Presentations.Open(PowerPointFile, msoFalse) 
End If 

ppProgram.Visible = True  
SlideNum = 1 

Set ppSlide = ppPres.Slides(SlideNum) ' set the slide 

' --- loop throughout the Slide shapes and search for the Shape of type chart , then delete the old ones 
For i = ppSlide.Shapes.Count To 1 Step -1 
    If ppSlide.Shapes.Item(i).HasChart Or ppSlide.Shapes.Item(i).Type = msoEmbeddedOLEObject Or ppSlide.Shapes.Item(i).Type = msoPicture Then 
     ppSlide.Shapes.Item(i).Delete 
    End If 
Next i 

' copy range from Excel Sheet 
OnePgrSht.Range("A1:Q33").Copy 

' ***** Error at the line below ***** 
Set myShape = ppSlide.Shapes.PasteSpecial(ppPasteEnhancedMetafile, msoFalse) ' Paste to PowerPoint  
' Set Pasted Picture object properties: 
With myShape 
    .LockAspectRatio = msoFalse 
    .Width = ExcelPicObj_Width 
    .Height = ExcelPicObj_Height 
    .Left = ExcelPicObj_Pos_Left 
    .Top = ExcelPicObj_Pos_Top 
    .ZOrder msoSendToBack 
End With 

ppPres.Save 
OnePgrSht.Activate ' <-- restore mouse focus on "One-Pager" sheet 

Set ppSlide = Nothing 
Set ppPres = Nothing 
Set ppProgram = Nothing 

End Sub 
+0

Um einen Bereich einzufügen, verwende ich normalerweise 'ppPasteHTML'. Nicht sicher, ob 'ppPasteEnhancedMetafile' für Bereiche verwendet werden kann ... – R3uK

+0

@ R3uK bist du sicher? Ich konnte "PasteSpecial" als "ppPasteEnhancedMetafile" verwenden, als ich ** Early Binding ** verwendete (bevor ich zu ** Late Binding ** wechselte) –

+0

Dunno, ich suche gerade im Web, habe nicht gefunden etwas Relevantes noch. Sie könnten den Bereich als "ppPasteEnhancedMetafile" in Early Binding einfügen? Also ich habe mich wahrscheinlich geirrt! Haben Sie etwas anderes als die Deklaration als Objekt geändert? – R3uK

Antwort

2

Die ppPasteEnhancedMetafile ist eine PowerPoint Konstante, die nicht verfügbar ist die späte Bindung verwenden. Dies liegt daran, dass die späte Bindung die Bibliothek PowerPoint, in der diese Konstante definiert ist, nicht enthält.

So haben Sie

Set myShape = ppSlide.Shapes.PasteSpecial(2, msoFalse) 

wo 2 = ppPasteEnhancedMetafile zu verwenden.

+0

I es verpasst! Aber sollte das nicht einen Kompilierungsfehler mit "Option Explicit" auslösen? – R3uK

+0

@Axel Richter Danke :) Das hat es geschafft.Noch eine Frage, was ist der Wert von 'ppAlignCenter'? Ich muss auch '.TextFrame.TextRange.Paragraphs.ParagraphFormat.Alignment = ppAlignCenter' ändern. –

+2

Was ich in diesen Fällen mache, googelt nach den konstanten Namen und findet dann meistens die Aufzählungen. Zum Beispiel: [PpParagraphAlignment Enumeration] (https://msdn.microsoft.com/en-us/library/bb251051%28v=office.12%29.aspx), das 'ppAlignCenter' enthält. –

Verwandte Themen