나는 매크로가있어서 Excel의 일부 데이터를 PowerPoint 프레젠테이션으로 내보내려고합니다. 파워 포인트에서 Excel의 제목을 일부 타이틀로 지정해야합니다. 여기 내 코드입니다 : VBA를 사용하여 PowerPoint에서 제목 설정
Sub CrearPresentacion2()
'Iniciar las variables
Dim rng As Excel.Range
Dim PowerPointApp As PowerPoint.Application
Dim myPresentation As PowerPoint.Presentation
Dim myShapeRange As PowerPoint.ShapeRange
'Pedir al usuario un rango de celdas
Set rng = Application.InputBox("Seleccione el Rango para hacer Presentación", Title:="Seleccionar Rango", Type:=8)
On Error Resume Next
'Hacer PowerPoint visible
PowerPointApp.Visible = True
PowerPointApp.Activate
'Crear Nueva Presentacion
Set myPresentation = PowerPointApp.Presentations.Add
'Ciclo para copiar cada celda en una diapositiva
For Each Cell In rng.Cells
Cell.Select
Selection.Copy
Dim ppSlide2 As PowerPoint.Slide
Dim x As Integer
x = myPresentation.Slides.Count + 1
If x = 1 Then
Set ppSlide2 = myPresentation.Slides.Add(Index:=x, Layout:=ppLayoutBlank)
PowerPointApp.ActivePresentation.Slides(x).Select
PowerPointApp.ActiveWindow.Selection.SlideRange.Select
Set myShapeRange = ppSlide2.Shapes.PasteSpecial(DataType:=ppPasteText)
Dim Header1 As String
Header1 = "Example"
Set myTitle = ppSlide2.Shapes.Title
myTitle.TextFrame.TextRange.Characters.Text = Header1
ElseIf x = 2 Then
Set ppSlide2 = myPresentation.Slides.Add(Index:=x, Layout:=ppLayoutBlank)
PowerPointApp.ActivePresentation.Slides(x).Select
PowerPointApp.ActiveWindow.Selection.SlideRange.Select
Set myShapeRange = ppSlide2.Shapes.PasteSpecial(DataType:=ppPasteText)
Else
Set ppSlide2 = myPresentation.Slides.Add(Index:=x, Layout:=ppLayoutText)
PowerPointApp.ActivePresentation.Slides(x).Select
PowerPointApp.ActiveWindow.Selection.SlideRange.Select
Set myShapeRange = ppSlide2.Shapes.PasteSpecial(DataType:=ppPasteText)
End If
Next Cell
CutCopyMode = False
카운터가 1과 동일
는, 내가 "예"제목을 삽입해야하지만, "myTitle이라는"개체가 존재하지 않는 것을 말한다. 두 번째 경우에, 나는 제목으로 셀을 둘 필요가 있지만 함수ppSlide2.Shapes.PasteSpecial 사용하는 방법을 모른다 (데이터 형식 : = ppPasteText)
감사합니다 너의 도움으로.
감사합니다. – rjara
대단히 환영합니다! :) –