change event images in worksheet

msaiyad

Board Regular
Joined
Mar 23, 2008
Messages
93
Hello please help in this code,
i have store some images on a folder i can see all images in worksheet at duble click event now i want to change this as selection change event
please help for this code


Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim MyFolder As String
Dim MyFile As String
Dim ws As Worksheet
Dim MyCell As Range ' cell for picture
Dim MyGallery As ShapeRange ' ALL PICTURES IN THE SHEET
'----------------------------------------------------------------------------
'- Folder & File name
MyFolder = "C:\Documents and Settings\abc\Desktop\tation\images\"
MyFile = MyFolder & Target.Value & ".jpg" ' CELL VALUE"
'------------------------------------------------------
Application.ScreenUpdating = False
Set ws = ActiveSheet
'------------------------------------------------------
'- clear all existing pictures
On Error Resume Next ' might be no pictures yet
Set MyGallery = ws.Pictures.ShapeRange
MyGallery.Delete
On Error GoTo 0 ' reset error trap to normal
'------------------------------------------------------
'- CELL SIZE
Set MyCell = ws.Range("E1")
MyCell.ColumnWidth = 30
MyCell.RowHeight = 200
'------------------------------------------------------
'- INSERT PICTURE & RESIZE TO SAME AS CELL

ws.Pictures.Insert(MyFile).Select
With Selection
.Top = MyCell.Top
.Left = MyCell.Left
.Width = MyCell.Width
.Height = MyCell.Height
.Placement = xlMoveAndSize
.PrintObject = True
End With
'------------------------------------------------------
'- remove focus from picture
MyCell.Select
Application.ScreenUpdating = True
End Sub
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

Forum statistics

Threads
1,223,711
Messages
6,174,020
Members
452,542
Latest member
Bricklin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top