jamiguel77
Active Member
- Joined
- Feb 14, 2006
- Messages
- 387
- Office Version
- 2016
- 2010
- 2007
- Platform
- Windows
- Web
hi, how to create a powerpoint document wit vba any link, any advice.
thanks
thanks
VBE >> Tools >> References >> Microsoft PowerPoint x.0 Object Library
Option Explicit
Sub CreatePowerPointPresentation()
'Set a reference to the PowerPoint object library for early binding
'VBE >> Tools >> References >> Microsoft PowerPoint x.0 Object Library
Dim ppApp As PowerPoint.Application
Dim ppPres As PowerPoint.Presentation
Dim ppSlide As PowerPoint.Slide
On Error Resume Next
'Get an instance of PowerPoint, if it already exists
Set ppApp = GetObject(, "PowerPoint.Application")
If ppApp Is Nothing Then
'Create a new instance of PowerPoint, since one does not already exist
Set ppApp = CreateObject("PowerPoint.Application")
'Make PowerPoint visible
ppApp.Visible = True
End If
On Error GoTo 0
'Create a new PowerPoint presentation
Set ppPres = ppApp.Presentations.Add
'Add a blank slide to the presentation
Set ppSlide = ppPres.Slides.Add(1, ppLayoutBlank)
'Do stuff here
'
'
'Clear from memory
Set ppApp = Nothing
Set ppPres = Nothing
Set ppSlide = Nothing
End Sub
Option Explicit
Sub CreatePowerPointPresentation()
Dim ppApp As Object 'PowerPoint.Application
Dim ppPres As Object 'PowerPoint.Presentation
Dim ppSlide As Object 'PowerPoint.Slide
On Error Resume Next
'Get an instance of PowerPoint, if it already exists
Set ppApp = GetObject(, "PowerPoint.Application")
If ppApp Is Nothing Then
'Create a new instance of PowerPoint, since one does not already exist
Set ppApp = CreateObject("PowerPoint.Application")
'Make PowerPoint visible
ppApp.Visible = True
End If
On Error GoTo 0
'Create a new PowerPoint presentation
Set ppPres = ppApp.Presentations.Add
'Add a blank slide to the presentation
Set ppSlide = ppPres.Slides.Add(1, 12) 'ppLayoutBlank
'Do stuff here
'
'
'Clear from memory
Set ppApp = Nothing
Set ppPres = Nothing
Set ppSlide = Nothing
End Sub
'Copy chart
cht.Chart.ChartArea.Copy
'Paste chart into slide
ppSlide.Shapes.Paste
With ppSlide
Set ppShape = .Shapes(.Shapes.Count)
End With
'Set properties for shape
With ppShape
'etc
'
'
End With
'Copy range (change the range accordingly)
Range("A2:B5").CopyPicture appearance:=xlScreen, Format:=xlPicture
'Paste range into slide
ppSlide.Shapes.Paste
With ppSlide
Set ppShape = .Shapes(.Shapes.Count)
End With
'Set properties for shape
With ppShape
'etc
'
'
End With
Dim ppShape As PowerPoint.Shape
Dim ppShape As Object
Dim ppApp As PowerPoint.Application
Dim ppPres As PowerPoint.Presentation
Dim ppSlide As PowerPoint.Slide
Dim ppShape As Object 'PowerPoint.Shape
On Error Resume Next
'Get an instance of PowerPoint, if it already exists
Set ppApp = GetObject(, "PowerPoint.Application")
If ppApp Is Nothing Then
'Create a new instance of PowerPoint, since one does not already exist
Set ppApp = CreateObject("PowerPoint.Application")
'Make PowerPoint visible
ppApp.Visible = True
End If
On Error GoTo 0
'Create a new PowerPoint presentation
Set ppPres = ppApp.Presentations.Add
'Add a blank slide to the presentation
Set ppSlide = ppPres.Slides.Add(1, ppLayoutBlank)
'Copy chart
Set NewSheet = wbk.Sheets("Graficas")
Set cht = NewSheet.ChartObjects("xBudget")
cht.Chart.ChartArea.Copy
'Paste chart into slide
ppSlide.Shapes.Paste
With ppSlide
Set ppShape = .Shapes(.Shapes.Count)
End With
'Set properties for shape
With ppShape
.Left = 40
.Top = 30
.Height = 200
.Width = 250
'etc
'
'
End With
Set ppSlide = ppPres.Slides.Add(1, 12) 'ppLayoutBlank
'Do stuff here
'
'
'Clear from memory
Set ppApp = Nothing
Set ppPres = Nothing
Set ppSlide = Nothing
Sub CreatePowerPointPres()
Dim ppApp As PowerPoint.Application
Dim ppPres As PowerPoint.Presentation
Dim ppSlide As PowerPoint.Slide
Dim ppShape As PowerPoint.Shape
Dim cht As ChartObject
Dim ChtArray As Variant
Dim TopArray, LeftArray, HeightArray, WidthArray As Variant
On Error Resume Next
'Get an instance of PowerPoint, if it already exists
Set ppApp = GetObject(, "PowerPoint.Application")
If ppApp Is Nothing Then
'Create a new instance of PowerPoint, since one does not already exist
Set ppApp = CreateObject("PowerPoint.Application")
ppApp.Visible = True
End If
On Error GoTo 0
'Create a new PowerPoint presentation
Set ppPres = ppApp.Presentations.Add
'Add a blank slide to the presentation
Set ppSlide = ppPres.Slides.Add(1, ppLayoutBlank)
'Define the charts we want to export along with their corresponding dimensions
ChtArray = Array(Sheet1.ChartObjects(1), Sheet1.ChartObjects(2), Sheet1.ChartObjects(3))
LeftArray = Array(50, 528, 50, 528)
TopArray = Array(70, 70, 300, 300)
HeightArray = Array(50, 528, 50, 528)
WidthArray = Array(70, 70, 300, 300)
For x = LBound(ChtArray) To UBound(ChtArray)
'Create a reference to the chart and copy it.
Set cht = ChtArray(x)
cht.Copy
'Paste shape into slide.
ppSlide.Shapes.Paste
'Create a reference to the shape we want to manipulate.
Set ppShape = ppSlide.Shapes(.Shapes.Count)
'Set properties for shape
With ppShape
.Left = LeftArray(x)
.Top = TopArray(x)
.Height = HeightArray(x)
.Width = WidthArray(x)
End With
'Add a new slide and set a reference to it.
Set ppSlide = ppPres.Slides.Add(ppPres.Slides.Count + 1, 12) 'ppLayoutBlank
'Change Slide Color to a blue background.
With ppSlide
.FollowMasterBackground = msoFalse
.Background.Fill.Solid
.Background.Fill.ForeColor.RGB = RGB(0, 45, 155)
End With
Next x
'Clear from memory
Set ppApp = Nothing
Set ppPres = Nothing
Set ppSlide = Nothing
End Sub