# VBA .Addpicture in powerpoint



## Robertvk (Nov 25, 2015)

VBA has an issue with the code I supply for adding a picture to a powerpoint.


```
Dim pic As Shape
Set pic = activeSlide.Shapes.AddPicture("C:\img\fclogo.jpg", msoCTrue, msoFalse, 100, 100)
```

The code actually works and inserts a picture. However, it does give me a 'Runtime error 13, Type mismatch". I can suppress the error with On error resume next, but I actually want to know why it returns an error.


Also, I have no idea how the MsoTriStrate works, I just tried the MsoCTtrue and it worked. If someone could explain the meaning of MsoTriState that would be very helpful.

Thanks


----------



## Gary's Student (Nov 25, 2015)

Consider:


```
Sub dural()
   Dim s As String
   Dim sld As Slide
   Dim shp As Shape
   Set sld = Application.ActiveWindow.View.Slide
   s = "http://www.dogbreedinfo.com/images26/PugPurebredDogFawnBlackMax8YearsOld1.jpg"
   Set shp = sld.Shapes.AddPicture(s, msoCTrue, msoFalse, 100, 100)
End Sub
```


----------



## Robertvk (Nov 25, 2015)

It doesn't work for me.

It gives me an error (Compile error: invalid qualifier).
To be clear, Im working in an excel sheet. Not from PowerPoint.  I'll add some more code for clarification.


```
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

newPowerPoint.Presentations.Add
newPowerPoint.Visible = True
newPowerPoint.ActivePresentation.Slides.Add newPowerPoint.ActivePresentation.Slides.Count + 1, ppLayoutText
newPowerPoint.ActiveWindow.View.GotoSlide newPowerPoint.ActivePresentation.Slides.Count

LastRow = 16
RowCount = LastRow
SlideCount = 16

y = 0
x = 0
Do Until y = 16

If y >= 1 Then
Set pptLayout = newPowerPoint.ActivePresentation.Slides(1).CustomLayout
Set pptSlide = newPowerPoint.ActivePresentation.Slides.AddSlide(1 + y, pptLayout)
Else: End If

Set activeSlide = newPowerPoint.ActivePresentation.Slides(newPowerPoint.ActivePresentation.Slides.Count)

Stop
On Error Resume Next
Set pic = activeSlide.Shapes.AddPicture("H:\A-VBA\Personeel bestand\fclogo.jpg", msoCTrue, msoFalse, 20, 20, 238, 101)
On Error GoTo 0
Stop



Set sld = Application.ActiveWindow.View.Slide
link = "H:\A-VBA\Personeel bestand\fclogo.jpg"

Set pic = sld.Shapes.AddPicture(link, msoCTrue, msoFalse, 20, 20, 238, 101)
```


----------



## RoryA (Nov 25, 2015)

You may simply need to change this:

```
Dim pic As Shape
```
to this:

```
Dim pic As PowerPoint.Shape
```


----------



## Robertvk (Nov 26, 2015)

You are correct! Thanks. However I think I will keep the On error Resume next function. If a picture is unavailable I would like it to keep on going. But I'm glad I learned something. 

Anyone able to tell me whats the use of the MsoTriStrate / MsoCTrue? I'm still wondering how it works.


----------

