I have written a macro to pop up an image (jpg) at the top of the excel sheet as per the content of the cell.
For example if the cell content is abcd xyz the picture abcd.jpg will popup. It is working perfectly in excel 2003 and in 2007 the picture size is irregular - too small to very large. Can somebody help. Following is the code in 2003
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
Dim PicWd As Single
Dim PicHt As Single
Dim PicLt As Single
Dim PicTp As Single
Dim RowWidth As Integer
Dim SizeOfFont As Integer
Dim Position As Integer
Dim TheDirectory1 As String
Dim TheDirectory2 As String
Dim StrPicFile
On Error Resume Next
If ActiveCell.Column <= 12 And Not IsEmpty(ActiveCell) Then
ActiveSheet.Shapes("Mypicture").Delete
TheDirectory01 = "X:\reports\AllPhotosW09\"
TheDirectory02 = "Y:\reports\AllPhotosW09\"
Application.ScreenUpdating = False
Position = InStr(1, Trim(ActiveCell.Value), " ")
If Position = 0 Then Position = InStr(1, Trim(ActiveCell.Value), "-")
If Position = 0 Then Position = InStr(1, Trim(ActiveCell.Value), "/")
If Not Position = 0 Then
BuyerCode = Left(Trim(ActiveCell.Value), Position - 1)
Else
BuyerCode = Trim(ActiveCell.Value)
End If
StrPicFile = TheDirectory01 & Trim(BuyerCode) & ".jpg"
If Not (Dir(StrPicFile) > "") Then
StrPicFile = TheDirectory02 & Trim(BuyerCode) & ".jpg"
End If
If (Dir(StrPicFile) > "") And ActiveSheet.Name = "Style" Then
ActiveSheet.Pictures.Insert(StrPicFile).Select
Selection.ShapeRange.ScaleWidth 1#, msoFalse, msoScaleFromTopLeft
Selection.ShapeRange.ScaleHeight 1#, msoFalse, msoScaleFromTopLeft
Selection.Name = "Mypicture"
HeightRatio = 200 / Selection.Height
Selection.Left = Cells(1, 2).Left
Selection.Top = Cells(1, 2).Top
Selection.Width = Selection.Width * HeightRatio
Selection.Height = Selection.Height * HeightRatio
ActiveCell.Select
End If
ActiveSheet.Calculate
End If
End Sub
Bookmarks