Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
dc dc is offline
external usenet poster
 
Posts: 2
Default Insert pictures

Hi everyone

I have several excel spreadsheets that has classlists of students. Each
spreadsheet has seperate columns for student number (eg 1234567), surname
(eg Blogg) and firstname (eg Joe). There is a folder that has photos of
students (jpegs), each photo is in a seperate file and the filename is
student_number.jpeg (eg 1234567.jpeg). I am looking to create another column
for photos in the spreadsheet and have a script that inserts the picture of
the student by fetching it from the folder which contains all the photos.
Any ideas on how to do this or the scripts from someone who has already done
this would be greatly appreciated.

Thanks in advance.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default Insert pictures

Hi DC

The following code is not a script but it might give you an idea of
one way to show pictures depending on the value of a cell. This code
will generate a rectangle shape beside the selected cell and fill it
with the picture providing the selected cell ends in the JPG
extension. I hope this is of some use to you it is a little ruff
round the edges but it should work. Just paste the code below into
the module for the worksheet that holds the information.

'To Change the Folder that holds the pictures amend both instances of
line
'Selection.ShapeRange.Fill.UserPicture --- "C:\Pics\" --- &
Target.Value
'To change the shape to portrait change both instances of the line to
read like below
'MyDoc.Shapes.AddShape(msoShapeRectangle, H, V, 100, 200).Select

Option Explicit
Dim H, V As Integer
Dim MyDoc
Dim i As Integer
Dim MyChk As String

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Set MyDoc = Sheets(1) 'Select which worksheet to work with

H = Target.Offset(0, 1).Left 'Gather details for placement of shape

V = Target.Offset(0, 1).Top

i = MyDoc.Shapes.Count 'Count shapes in the active worksheet

MyChk = Right(Target.Value, 4)


If Target.Cells.Count 1 Then 'Check if a range is selected

ClearShape

Exit Sub

End If

If Target.Value = "" Then 'Check if selected cell is empty

ClearShape

Exit Sub

End If

If MyChk = ".JPG" Then 'Check cell value ends with the JPG extension

If i 1 Then 'If a shape is open delete it then open a new one in
the new location

MyDoc.Shapes("Comment").Select

Selection.Delete

MyDoc.Shapes.AddShape(msoShapeRectangle, H, V, 200,
100).Select

Selection.Name = "Comment" 'Name the shape

Selection.ShapeRange.Fill.UserPicture "C:\Pics\" &
Target.Value
'line above will put the picture in the shape
Else

MyDoc.Shapes.AddShape(msoShapeRectangle, H, V, 200,
100).Select

Selection.Name = "Comment"

Selection.ShapeRange.Fill.UserPicture "C:\Pics\" &
Target.Value

End If

Else 'If the cell doesn't end with the JPG extension exit sub

ClearShape

Exit Sub

End If

End Sub
Sub ClearShape()

If i 1 Then 'If a shape is open close it

MyDoc.Shapes("Comment").Select

Selection.Delete

End If

End Sub

Take it easy

S



  #3   Report Post  
Posted to microsoft.public.excel.programming
dc dc is offline
external usenet poster
 
Posts: 2
Default Insert pictures

Many thanks for that. Works well with a slight bit of tweaking to suit our
purpose.

Much appreciated.
DC


"Incidental" wrote in message
ups.com...
Hi DC

The following code is not a script but it might give you an idea of
one way to show pictures depending on the value of a cell. This code
will generate a rectangle shape beside the selected cell and fill it
with the picture providing the selected cell ends in the JPG
extension. I hope this is of some use to you it is a little ruff
round the edges but it should work. Just paste the code below into
the module for the worksheet that holds the information.

'To Change the Folder that holds the pictures amend both instances of
line
'Selection.ShapeRange.Fill.UserPicture --- "C:\Pics\" --- &
Target.Value
'To change the shape to portrait change both instances of the line to
read like below
'MyDoc.Shapes.AddShape(msoShapeRectangle, H, V, 100, 200).Select

Option Explicit
Dim H, V As Integer
Dim MyDoc
Dim i As Integer
Dim MyChk As String

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Set MyDoc = Sheets(1) 'Select which worksheet to work with

H = Target.Offset(0, 1).Left 'Gather details for placement of shape

V = Target.Offset(0, 1).Top

i = MyDoc.Shapes.Count 'Count shapes in the active worksheet

MyChk = Right(Target.Value, 4)


If Target.Cells.Count 1 Then 'Check if a range is selected

ClearShape

Exit Sub

End If

If Target.Value = "" Then 'Check if selected cell is empty

ClearShape

Exit Sub

End If

If MyChk = ".JPG" Then 'Check cell value ends with the JPG extension

If i 1 Then 'If a shape is open delete it then open a new one in
the new location

MyDoc.Shapes("Comment").Select

Selection.Delete

MyDoc.Shapes.AddShape(msoShapeRectangle, H, V, 200,
100).Select

Selection.Name = "Comment" 'Name the shape

Selection.ShapeRange.Fill.UserPicture "C:\Pics\" &
Target.Value
'line above will put the picture in the shape
Else

MyDoc.Shapes.AddShape(msoShapeRectangle, H, V, 200,
100).Select

Selection.Name = "Comment"

Selection.ShapeRange.Fill.UserPicture "C:\Pics\" &
Target.Value

End If

Else 'If the cell doesn't end with the JPG extension exit sub

ClearShape

Exit Sub

End If

End Sub
Sub ClearShape()

If i 1 Then 'If a shape is open close it

MyDoc.Shapes("Comment").Select

Selection.Delete

End If

End Sub

Take it easy

S





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't insert pictures laurie New Users to Excel 2 April 5th 23 01:21 PM
Insert pictures AZU Excel Discussion (Misc queries) 5 March 6th 09 05:28 PM
Need Help with auto insert of pictures Bradley Wolosz New Users to Excel 3 August 25th 08 12:28 PM
Insert pictures TheRook Excel Programming 4 August 11th 06 02:58 PM
using VBA to insert a column of pictures andy hackett Excel Programming 14 June 28th 04 08:45 AM


All times are GMT +1. The time now is 06:01 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"