从Excel创建PowerPoint演示文稿

时间:2016-04-07 08:39:37

标签: excel vba

我正在尝试从Excel电子表格制作PP幻灯片。我有这个VBA模块:

     Sub CreatePowerPointQuestions()
    Dim newPowerPoint As PowerPoint.Application
    Dim activeSlide As PowerPoint.Slide
    Dim Question As String
    Dim Options As String
    Dim Answer As String
    Dim limit As Integer

    limit = 3
    On Error Resume Next
Set newPowerPoint = GetObject(, "PowerPoint.Application")
On Error GoTo 0
If newPowerPoint Is Nothing Then
    Set newPowerPoint = New PowerPoint.Application
End If

   'Make a presentation in PowerPoint
  If newPowerPoint.Presentations.Count = 0 Then
    newPowerPoint.Presentations.Add
  End If

'Show the PowerPoint
newPowerPoint.Visible = True
'Select worksheet and cells activate
Worksheets("Sheet1").Activate

'Loop through each question
For i = 1 To limit

'Add a new slide where we will paste the Question and Options:
    newPowerPoint.ActivePresentation.Slides.Add newPowerPoint.ActivePresentation.Slides.Count + 1, 3
    newPowerPoint.ActiveWindow.View.GotoSlide newPowerPoint.ActivePresentation.Slides.Count
    Set activeSlide = newPowerPoint.ActivePresentation.Slides(newPowerPoint.ActivePresentation.Slides.Count)

'Set the variables to the cells
    Question = ActiveSheet.Cells(i, 1).Value
    Options = ActiveSheet.Cells(i, 2).Value
    Answer = ActiveSheet.Cells(i, 3).Value


    activeSlide.Shapes(1).TextFrame.TextRange.Text = Question
    activeSlide.Shapes(2).TextFrame.TextRange.Text = Options

    activeSlide.Shapes(3).TextFrame.TextRange.Text = Answer

Next


Set activeSlide = Nothing
Set newPowerPoint = Nothing



End Sub

问题在于它创建了带有标题的幻灯片和带有子弹的两个条目。我希望幻灯片是三行,没有子弹。有没有办法做到这一点?我不知道怎么做布局

1 个答案:

答案 0 :(得分:0)

您可以在https://msdn.microsoft.com/en-us/library/office/ff745137.aspx

中使用一系列布局

但是,只有两个符合您的标准

  • ppLayoutObjectOverText和
  • ppLayoutTextOverObject

Set activeslide行之后尝试此操作:

    activeSlide.layout = ppLayoutObjectOverText