kato01
03-10-2014, 12:00 PM
Hello,
I am just trying to ad a new slide plus some text to an exiting ppt file.
I can't understand why this does not work.
Please advise
Thank you
Kato01
Sub writeToPPT()
'Add a reference to Microsoft Powerpoint 12.0 object library
Dim oPPTApp As PowerPoint.Application
Dim oPPTFile As PowerPoint.Presentation
Dim oPPTShape As PowerPoint.Shape
Dim oPPTSlide As PowerPoint.Slide
Set oPPTApp = CreateObject("PowerPoint.Application")
oPPTApp.Visible = msoTrue
'opening an existing presentation
'Change the path and presentation name
Set oPPTFile = oPPTApp.Presentations.Open(Filename:="Y:\D\(0)_OFFICE\MySimulations\My Simulations 20140204.pptM")
oPPTFile.Slides.Add Index:=oPPTFile.Slides.Count + 1, Layout:=ppLayoutBlank
NS = oPPTFile.Slides.Count
'Write to the first shape on first slide
Set oPPTShape = oPPTFile.Slides(2).Shapes(1)
With oPPTShape.TextFrame.TextRange
.Font.Size = 12
.Font.Color = vbRed
.Font.Underline = msoTrue
.Text = "Add some sample text." & vbCrLf _
& "Line 2 to add some more text" & vbCrLf _
& "Line 3 to add even more text"
End With
'Add cleanup code
End Sub
I am just trying to ad a new slide plus some text to an exiting ppt file.
I can't understand why this does not work.
Please advise
Thank you
Kato01
Sub writeToPPT()
'Add a reference to Microsoft Powerpoint 12.0 object library
Dim oPPTApp As PowerPoint.Application
Dim oPPTFile As PowerPoint.Presentation
Dim oPPTShape As PowerPoint.Shape
Dim oPPTSlide As PowerPoint.Slide
Set oPPTApp = CreateObject("PowerPoint.Application")
oPPTApp.Visible = msoTrue
'opening an existing presentation
'Change the path and presentation name
Set oPPTFile = oPPTApp.Presentations.Open(Filename:="Y:\D\(0)_OFFICE\MySimulations\My Simulations 20140204.pptM")
oPPTFile.Slides.Add Index:=oPPTFile.Slides.Count + 1, Layout:=ppLayoutBlank
NS = oPPTFile.Slides.Count
'Write to the first shape on first slide
Set oPPTShape = oPPTFile.Slides(2).Shapes(1)
With oPPTShape.TextFrame.TextRange
.Font.Size = 12
.Font.Color = vbRed
.Font.Underline = msoTrue
.Text = "Add some sample text." & vbCrLf _
& "Line 2 to add some more text" & vbCrLf _
& "Line 3 to add even more text"
End With
'Add cleanup code
End Sub