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

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 ShapeDim 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 pictureSet
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" slzeWith
oPicture .Scaleheight 1, msoTrue .Scalewidth 1, msoTrueEnd
with Set oPicture = NothingEnd SubThanks
Tiger
 
S

Steve Rindsberg

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 ShapeDim 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 pictureSet
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" slzeWith
oPicture .Scaleheight 1, msoTrue .Scalewidth 1, msoTrueEnd
with Set oPicture = NothingEnd SubThanks
Tiger

If that's really what you've got as VBA, I can imagine PPT would get a bit
ruffled over it. Somebody done sucked all the spaces 'n stuff out of it.

Try this instead, let us know if it flies more gracefully:

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
 

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