简体   繁体   中英

Create PowerPoint presentation from Excel

I'm trying to make a PP slideshow from an Excel spreadsheet. I have this VBA module:

     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

The problem is that it creates slides with a title and two entries side by side with a bullet. I want the slide to be three lines, without the bullets. Is there a way to do this? I don't know how to do the layouts

There is a list of layouts that you can use at https://msdn.microsoft.com/en-us/library/office/ff745137.aspx

However, only two of them match your criteria

  • ppLayoutObjectOverText, and
  • ppLayoutTextOverObject

Try this after your Set activeslide line:

    activeSlide.layout = ppLayoutObjectOverText

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM