insert a picture based on a linked value

S

Steve Rindsberg

Using VBA insert a picture for a linked value from Excel in PowerPoint slide
show

That could be interpreted in several ways. You'll need to describe what you
want to do in more detail.
 
G

Guest

Steve;
I have linked values from excel embedded in my slideshows I would like to
insert a bmp based on the value embedded. In excel I was able to do it using
the worksheet_change, but I don't know enough in PowerPoint.

Here is the code I used in Excel, but I would Like to do the same in
PowerPoint:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$C$28" Then
Application.EnableEvents = False
HandleBMP
Application.EnableEvents = True
End If
End Sub

Sub HandleBMP()
Dim myCell As Range
Set myCell = Selection

On Error Resume Next
If Range("C28").Value >= 90 Then
MsgBox "Insert Stoplight"
ActiveSheet.Shapes("C28 Picture").Delete
Range("F22").Select
ActiveSheet.Pictures.Insert( _
"C:\grn-lght.bmp").Select
Selection.Name = "C28 Picture"

ElseIf Range("C28").Value >= 78 Then
MsgBox "Insert Stoplight"
ActiveSheet.Shapes("C28 Picture").Delete
Range("F22").Select
ActiveSheet.Pictures.Insert( _
"C:\yellow-lght.bmp").Select
Selection.Name = "C28 Picture"

On Error Resume Next
ElseIf Range("C28").Value < 78 Then
MsgBox "Insert Stoplight"
ActiveSheet.Shapes("C28 Picture").Delete
Range("F22").Select
ActiveSheet.Pictures.Insert( _
"C:\red-lght.bmp").Select
Selection.Name = "C28 Picture"

Else
MsgBox "Deleting"
ActiveSheet.Shapes("C28 Picture").Delete

End If

Else
MsgBox "Deleting"
ActiveSheet.Shapes("C417 Picture").Delete

End If

myCell.Select
End Sub

Thanks for all the help
 
S

Steve Rindsberg

Steve;
I have linked values from excel embedded in my slideshows I would like to
insert a bmp based on the value embedded. In excel I was able to do it using
the worksheet_change, but I don't know enough in PowerPoint.

Here is the code I used in Excel, but I would Like to do the same in
PowerPoint:

Two problems, then.

One is retrieving the value from the linked Excel sheet.

You can probably use something very like the code you're already using, but
with some mods to allow you to automate Excel/the linked or embedded data
from PPT. This'll give you a good place to start:

Automate Excel from PowerPoint. Automate PowerPoint from Excel. And so on.
http://www.rdpslides.com/pptfaq/FAQ00368.htm

The other problem is inserting a bitmap once you've worked out the name and
location. This should help with that:

Insert a picture at the correct size
http://www.rdpslides.com/pptfaq/FAQ00329.htm

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$C$28" Then
Application.EnableEvents = False
HandleBMP
Application.EnableEvents = True
End If
End Sub

Sub HandleBMP()
Dim myCell As Range
Set myCell = Selection

On Error Resume Next
If Range("C28").Value >= 90 Then
MsgBox "Insert Stoplight"
ActiveSheet.Shapes("C28 Picture").Delete
Range("F22").Select
ActiveSheet.Pictures.Insert( _
"C:\grn-lght.bmp").Select
Selection.Name = "C28 Picture"

ElseIf Range("C28").Value >= 78 Then
MsgBox "Insert Stoplight"
ActiveSheet.Shapes("C28 Picture").Delete
Range("F22").Select
ActiveSheet.Pictures.Insert( _
"C:\yellow-lght.bmp").Select
Selection.Name = "C28 Picture"

On Error Resume Next
ElseIf Range("C28").Value < 78 Then
MsgBox "Insert Stoplight"
ActiveSheet.Shapes("C28 Picture").Delete
Range("F22").Select
ActiveSheet.Pictures.Insert( _
"C:\red-lght.bmp").Select
Selection.Name = "C28 Picture"

Else
MsgBox "Deleting"
ActiveSheet.Shapes("C28 Picture").Delete

End If

Else
MsgBox "Deleting"
ActiveSheet.Shapes("C417 Picture").Delete

End If

myCell.Select
End Sub

Thanks for all the help

 

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