PDA

View Full Version : Help inserting picture into slide



sharky12345
09-20-2013, 12:30 PM
I'm very new to VBA and how it can work with Powerpoint so I'd be grateful if someone can give me some help with this;

I want to put a picture on a slide to the right hand side of some text - ideally I'd like to be able to navigate to the picture location from a userform and then enter the picture by the click of a commandbutton on the userform. The text is entered by code like this;
Sub CreatePowerPoint2()

'Add a reference to the Microsoft PowerPoint Library by:
'1. Go to Tools in the VBA menu
'2. Click on Reference
'3. Scroll down to Microsoft PowerPoint X.0 Object Library, check the box, and press Okay

'First we declare the variables we will be using
Dim newPowerPoint As PowerPoint.Application
Dim activeSlide As PowerPoint.Slide
Dim cht As Excel.ChartObject

'Look for existing instance
On Error Resume Next
Set newPowerPoint = GetObject(, "PowerPoint.Application")
On Error GoTo 0

'Let's create a new PowerPoint
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

'Loop through each chart in the Excel worksheet and paste them into the PowerPoint


'Add a new slide where we will paste the chart
newPowerPoint.ActivePresentation.Slides.Add newPowerPoint.ActivePresentation.Slides.Count + 1, ppLayoutText
newPowerPoint.ActiveWindow.View.GotoSlide newPowerPoint.ActivePresentation.Slides.Count
Set activeSlide = newPowerPoint.ActivePresentation.Slides(newPowerPoint.ActivePresentation.Sl ides.Count)

'Copy the chart and paste it into the PowerPoint as a Metafile Picture


'Set the title of the slide the same as the title of the chart


'Adjust the positioning of the Chart on Powerpoint Slide

'If the chart is the "US" consumption chart, then enter the appropriate comments
activeSlide.Shapes(1).TextFrame.TextRange.Text = Range("B11").Value & vbNewLine
activeSlide.Shapes(2).TextFrame.TextRange.Text = Range("B13").Value & vbNewLine & vbNewLine


'Now let's change the font size of the callouts box
activeSlide.Shapes(2).TextFrame.TextRange.Font.Size = 22

AppActivate ("Microsoft PowerPoint")
Set activeSlide = Nothing
Set newPowerPoint = Nothing
End Sub
so can anyone help me insert the picture but to the right of the existing text? I appreciate the code needs tidying up but I'm just playing around with it at the moment!