Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 04-23-2012, 02:02 PM
CatMan CatMan is offline Need help to insert a picture (.jpg) into slide 1 of an existing PowerPoint Windows 7 32bit Need help to insert a picture (.jpg) into slide 1 of an existing PowerPoint Office 2010 32bit
Intermediate
Need help to insert a picture (.jpg) into slide 1 of an existing PowerPoint
 
Join Date: Apr 2012
Posts: 39
CatMan is on a distinguished road
Default Need help to insert a picture (.jpg) into slide 1 of an existing PowerPoint

Hello forum and thanks to all for taking the time to look at this.

I am trying to insert (addpicture) a .jpg picture into slide 1 of an existing PowerPoint file using Excel VBA (Excel is host). I am getting run-time error 91, "Object variable or with block variable not set.". I have included code to resize and center the picture on the slide, I believe these two blocks work but I cannot test it until the addpicture method is solved. I have tried to set various objects to solve the problem but I am not clear which 'with block' is missing.

Here is a much simplified version of my code, the line that is failing is marked "Add Picture": (The code must run in an Excel module)



Code:
Sub TestCode()
'Declare
Dim oPA As PowerPoint.Application
Dim oPP As PowerPoint.Presentation
Dim oPS As PowerPoint.Slide
Dim oShape As PowerPoint.Shape
Dim oPicture As PowerPoint.Shape
 
'Set path and fielname of existing PowerPoint
'ExistingPPT = "Libraries\Documents\Test.pptx" 'make sure presentation has one blank slide.
 
'Set path and filename of picture to be imported into ppt
MyPicture = "Libraries\Documents\Tara1.jpg"
 
'Open Existing PowerPoint
Set ppt = CreateObject("PowerPoint.Application")
With ppt
    'Open existing PowerPoint (THIS BLOCK WORKS)
    .Visible = True
    .Presentations.Open (existingPPT)
    .ActiveWindow.View.GotoSlide (1) 'this line makes testing easier otherwise not required
 
   'Add Picture (e.g. import it into PPT) (THIS BLOCK DOES NOT WORK)
    Set oShape = oPS.Shapes.AddPicture(MyPicture, msoFalse, msoTrue, 1, 1, -1, -1) '(Filename, LinkToFile, SaveWithDocument, Left, Top, Width, Height)
 
   'Size Picture
    Set oPicture = oPS.Shapes(oPSe.Shapes.Count)
    oPicture.ScaleHeight 1, msoTrue
    oPicture.ScaleWidth 1, msoTrue
    oPicture.LockAspectRatio = True
    oPicture.Width = 750 '750 is arbitrary
 
   'Center picture
    With oPA.ActivePresentation.PageSetup
        oPicture.Left = (.SlideWidth \ 2) - (oPicture.Width \ 2)
        oPicture.Top = (.SlideHeight \ 2) - (oPicture.Height \ 2)
    End With
End With
 
End Sub

Last edited by CatMan; 04-23-2012 at 03:03 PM.
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help to insert a picture (.jpg) into slide 1 of an existing PowerPoint How to insert hidden chapter markers (headings) into existing Word outline? GKent Word 4 04-16-2012 08:52 AM
Powerpoint automatically changing picture size when adding a picture (2010) One_Life PowerPoint 7 01-20-2012 06:57 AM
PowerPoint 2003 - Change default location for Insert Picture Fee PowerPoint 0 05-12-2011 02:15 AM
How to insert a reference to an existing endnote dwschulze Word 0 01-23-2010 08:59 AM
Apply design template to existing slide mellowyellow PowerPoint 0 01-26-2009 12:59 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:18 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft