2017-12-14 2 views
0

저는 현재 PowerShell의 자동화를 통해 Excel에서 테이블을 작성하고 있습니다. 이 단계는 훌륭하게 작동하며 테이블은 내가 원하는대로 끝납니다. 이제 PowerPoint 프레젠테이션에 붙여 넣으 려합니다.Excel에서 PowerPoint로 테이블 붙여 넣기에 가장 좋은 방법은 (소스 서식 유지)

PowerPoint 프레젠테이션은 내가 만든 템플릿으로 다른 요소로 채워집니다. 나는이 부분과 별개로 모든 부분을 분해했다고 생각한다.

이미 백그라운드에서 열려있는 Excel 파일에서 붙여 넣으려고합니다. 지금까지는 활성화되어 있고 원하는 범위가 선택되었습니다. 그런 다음 PowerPoint 창에 붙여 넣습니다. 그러나 형식이없는 회색 표로 제공됩니다.

이전에 템플릿을 정리하고 다른 구성 요소를 수동으로 테스트 할 때 아래 줄은 Excel에서 붙여 넣기를 수행하여 완벽했습니다.

ActivePresentation.Application.CommandBars.ExecuteMso "PasteExcelTableSourceFormatting" 

그러나 자동화 (다른 창과 상호 작용 등)로 이동하면 더 이상 작동하지 않습니다. 대신 "ActiveX 구성 요소를 만들 수 없습니다."오류를 제공합니다. 아래

전체 코드 :

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 

답변

0

는, 그것을 해결하기 위해 이미 일하고 매우 유사한 조치에 대한 코드를 확인하기 위해 생각하지 않았다 믿을 수 없어 관리! 나는 다음을 사용 했어야했다 :

PPPres.Application.CommandBars.ExecuteMso "PasteExcelTableSourceFormatting" 
관련 문제