0
我是新的宏,我试图导出一些数据从Excel到PowerPoint演示文稿。我需要将Excel中的某些单元格作为PowerPoint中的标题。这里是我的代码:使用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
非常欢迎! :) –