Error message "object variable or with block varible not set" Help.

T

tiger

Hi,

I have the following VBA code for PowerPoint.....and I this error message
"object variable or with block varible not set".

Sub InsertAndSizePicture()

Dim oPicture as Shape
Dim FullPath as String

' Set this to the full path to picture.
FullPath ="C:\My Documents\Pictures\MyPhoto.JPG"

' Insert the picture at an arbitrary size;
' PowerPoint requires you to supply *some* height and width for the picture
Set oPicture = ActiveWindow.Selection.Shapes.AddPicture (Filename:=FullPath,
_
LinkToFile:=msoFalse, _
SaveWithDocument:=msoFalse, _
Left:=0, Top:=0, _
width:=100, height:=100)

' Rescale the picture to its "natural" slze
With oPicture
.Scaleheight 1, msoTrue
.Scalewidth 1, msoTrue
End with

Set oPicture = Nothing

End Sub
 
A

Austin Myers

Try this;

Set myDocument = ActivePresentation.Slides(1)
myDocument.Shapes.AddPicture FileName:="c:\microsoft office\" & _
"clipart\music.bmp", LinkToFile:=msoTrue, SaveWithDocument:=msoTrue, _
Left:=100, Top:=100, Width:=70, Height:=70


I believe the LinkToFile and SaveWithDocument are required.


Austin Myers
MS PowerPoint MVP Team

PowerPoint Video and PowerPoint Sound Solutions www.pfcmedia.com
 
G

Glen Millar

Hi,

You are missing the SlideRange part as in below................

Mine which works:
Set oPicture =
ActiveWindow.Selection.SlideRange.Shapes.AddPicture(FileName:=FullPath,
LinkToFile:=msoFalse, SaveWithDocument:=msoTrue, Left:=284, Top:=84,
Width:=152, Height:=373)

Yours which doesn't:
Set oPicture = ActiveWindow.Selection.Shapes.AddPicture (Filename:=FullPath,
LinkToFile:=msoFalse, SaveWithDocument:=msoTrue, Left:=0, Top:=0,
width:=100, height:=100)


--

Regards,

Glen Millar
Microsoft PPT MVP
www.powerpointworkbench.com

Australia

glen at powerpointworkbench dot com

Please tell us your PowerPoint and Windows
version, whether you are using vba,
whether your dog has fleas, or
anything else relevant.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top