Issue with adding pictures to PowerPoint via using Access (1 Viewer)

fkneg1

Registered User.
Local time
Today, 10:19
Joined
Aug 11, 2013
Messages
23
I am using VBA to make a PowerPoint presentation based on data in an Access query. I am having issues with adding a picture to the presentation. I have the following bit of code which works to add the picture as long as it is right at the beginning of the code (ie. the last powerpoint slide):
Code:
                     With .Slides.Add(rs.AbsolutePosition + 1, ppLayoutBlank)
                        .FollowMasterBackground = False
                        .Background.Fill.Solid
                        .Background.Fill.ForeColor.RGB = RGB(255, 255, 255)
                        .SlideShowTransition.EntryEffect = ppEffectFade
                        .Shapes.AddPicture(FileName:="D:\Desktop\JDJ\ECC\PowerPoints\ECClogo.jpg", LinkToFile:=msoFalse, SaveWithDocument:=msoTrue, Left:=168, Top:=134, Width:=592, Height:=191).Select
                    End With

But if I try and put it anywhere else in the code the picture is added fine but the code stops running and I get 'Run-time error '-2147188169 (80048240) Method 'Select' of object 'Shape' failed' with the error on the Shapes.AddPicture... line.
Any ideas on how to fix this?
 

Rx_

Nothing In Moderation
Local time
Today, 03:19
Joined
Oct 22, 2009
Messages
2,803
The VBA from Excel will be very much the same.
Just a guess here - but it is probably necessary to modify the code to put each successive picture two rows below the previous.
In the case of adding your data before, it might be a conflict in spacing too.


Code:
Sub INSERTINGPICTURE()
  'for inserting picture and not saving picture with workbook (or access in your case) for saving space
  Dim ws As Worksheet, MYPICT As String, tp As Double, lef As Double
  Set ws = ActiveSheet
  
  MYPICT = Application.GetOpenFilename
  
  lef = Range("G10").Left
  If ws.Shapes.Count = 0 Then
    tp = Range("G10").Top
  Else
    tp = ws.Shapes(ws.Shapes.Count).BottomRightCell.Offset(2).Top
  End If
  
  ws.Shapes.AddPicture MYPICT, True, False, lef, tp, 200, 200
End Sub

In your code, the location and spacing between Add Picture may be conflicting with other objects. Since it works if it is first, the picture is on a blank slide not conflicting with anything.
Code:
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

http://www.access-programmers.co.uk/forums/showthread.php?t=250949
That might be why I chose to use Shapes in my demo.
Sorry I can be more help, have a deadline to meet today.

http://social.msdn.microsoft.com/Fo...doesnt-take-selected-placeholder-into-account
Added this, will have to research this myself at a later time. Looks like there is a placeholder issue in Powerpoint.
 
Last edited:

Rx_

Nothing In Moderation
Local time
Today, 03:19
Joined
Oct 22, 2009
Messages
2,803
I reserve the right to change my mind... often and with out warning.
Now, it appears that an Index is missing.
Set objShape = ObjSlide.Shapes(Index).AddPicture(strImg, msoFalse, msoTrue, 0, 0, 300, 500)

Code:
' - set reference to Powerpoint 
'   Go to the "Project" menu, and select "References".
'   Select a  "Microsoft Powerpoint X.X Object Library"
Private Sub Command1_Click()
    Dim ppApp As PowerPoint.Application
    Dim ppPrsn As PowerPoint.Presentation
    Dim ppSlide As PowerPoint.Slide
    Dim objShape As PowerPoint.Shape
    
    Dim strTemplateFile As String, strImg As String
    
    Set ppApp = New PowerPoint.Application
    ppApp.Visible = True
    
    strTemplateFile = "C:\temp\template.ppt"
    strImg = "C:\temp\tst.jpg"

    Set ppPrsn = ppApp.Presentations.Open(strTemplateFile)
    ' note use of index (1) 
    Set objShape = ppPrsn.Slides(1).Shapes.AddPicture(strImg, False, True, 0, 0, 300, 500)
    
    objShape.ScaleHeight 1, msoTrue
    objShape.ScaleWidth 1, msoTrue
End Sub

The MSDN article above shows the loops for the index.
He takes the easy way out and suggest creating a template.
 

Users who are viewing this thread

Top Bottom