2017-12-14 4 views
0

Ich baue gerade eine Tabelle in Excel durch Automatisierung in PowerShell. Diese Schritte funktionieren großartig, der Tisch endet genau so, wie ich es mag. Ich möchte das jetzt in eine PowerPoint-Präsentation einfügen.Die beste Methode, um Tabellen aus Excel in PowerPoint einzufügen (Quellformatierung beibehalten)

Die PowerPoint-Präsentation ist eine Vorlage, die ich erstellt habe, die dann mit anderen Elementen ausgefüllt wird. Ich denke, ich habe jeden Teil abgesehen von diesem gebrochen.

Ich möchte aus der Excel-Datei einfügen, die bereits im Hintergrund geöffnet ist. Bis jetzt ist es aktiviert und der gewünschte Bereich ausgewählt. Es wird dann in das PowerPoint-Fenster eingefügt. Es kommt jedoch als graue Tabelle mit keiner der Formatierungen durch.

Zuvor beim Erstellen meiner Vorlage und beim manuellen Testen der verschiedenen Komponenten, die Zeile unten hat die Paste von Excel und es war perfekt.

Seit dem Umzug in die Automatisierung (und Interaktion mit verschiedenen Fenstern usw.) funktioniert es nicht mehr. Stattdessen wird der Fehler "Kann ActiveX-Komponente nicht erstellen" ausgegeben.

Voll Code unten:

Function CreateFLUTemplate(templateFile As String, PresPath As Variant, TalkingPointsDoc As Variant, LineOfBusiness As String, PolicyLink As String) 

' Declare variables to be used 
Dim PPApp As PowerPoint.Application 
Dim PPPres As PowerPoint.Presentation 
Dim WordApp As Word.Application 
Dim PPFile As Object, WordDoc As Object 
Dim TitleBox As PowerPoint.Shape, MetricsHeader As PowerPoint.Shape, MetricsTable As PowerPoint.Shape, PhishingHeader As PowerPoint.Shape, PhishingTable As PowerPoint.Shape 
Dim PolicyHeader As PowerPoint.Shape, PolicyBox As PowerPoint.Shape, TalkingPointsHeader As PowerPoint.Shape, TalkingPointsBox As PowerPoint.Shape, shp As PowerPoint.Shape 
Dim PPSlide As Slide 
Dim WAIT As Double 
Dim ShapeArray As Variant, LabelsArray As Variant, DateLabel As Variant 
Dim i As Integer 

' Open blank presentation file to be updated 
Set PPApp = CreateObject("PowerPoint.Application") 
PPApp.Visible = msoTrue 
Set PPFile = PPApp.Presentations.Open(PresPath) 
Set PPPres = PPApp.ActivePresentation 

' Construct date that will be used in the header sections 
DateLabel = Format(DateSerial(Year(Date), Month(Date), 0), "d mmmm yyyy") 

' Set slide object so we can set our shape variables etc 
Set PPSlide = PPPres.Slides(1) 

' Copy finished Excel table 

' Activate Spreadsheet with table to be copied 
Windows(templateFile).Activate 
Range("A1:E10").Copy 

PPApp.Windows(1).Activate 
' Paste Excel table in to PowerPoint 
'ActivePresentation.Application.CommandBars.ExecuteMso "PasteExcelTableSourceFormatting" 
'PPPres.Slides(1).Shapes.PasteSpecial(DataType:=ppPasteShape).Select 
PPApp.ActivePresentation.Slides(1).Shapes.Paste 

' Introduce delay to let paste action happen before moving on 
WAIT = Timer 
While Timer < WAIT + 0.5 
    DoEvents 
Wend 

' Take pasted table and save to object 
If PPApp.ActiveWindow.Selection.Type = ppSelectionNone Then 
    MsgBox "Nothing is selected", vbExclamation 
Else 
    For Each shp In PPApp.ActiveWindow.Selection.ShapeRange 
     Set MetricsTable = PPApp.ActivePresentation.Slides(1).Shapes(shp.Name) 
    Next shp 
End If 

' Reposition and resize pasted table. 
With MetricsTable 
    .Left = 27 
    .Top = 108 
    .Width = 363 
    .Table.Columns(1).Width = 148 
    .Table.Columns(2).Width = 28 
    .Table.Columns(3).Width = 28 
    .Table.Columns(4).Width = 28 
    .Table.Columns(5).Width = 131 
    .Height = 227 
End With 

Antwort

0

Managed es zu beheben, ich kann nicht glauben nicht denken, den Code für eine sehr ähnliche Maßnahmen zu prüfen, die bereits tätig war! Ich hätte verwenden sollen:

PPPres.Application.CommandBars.ExecuteMso "PasteExcelTableSourceFormatting" 
Verwandte Themen