VBA .Addpicture in powerpoint

Robertvk

Board Regular
Joined
Oct 15, 2015
Messages
121
VBA has an issue with the code I supply for adding a picture to a powerpoint.

Code:
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
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Consider:

Code:
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
 
Upvote 0
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.

Code:
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)
 
Upvote 0
You may simply need to change this:
Code:
Dim pic As Shape
to this:
Code:
Dim pic As PowerPoint.Shape
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,749
Members
448,989
Latest member
mariah3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top