G
Guest
Dear All
I have below code it's to insert photo in the cell and adjust the size
automatically as the row and Colum width and height, it's working perfect in
excel 2003, but in excel 2007 not working as I need, now only inserting the
photo without adjust it automatically .
Can anyone help me to modify the code to work in excel 2007
=============
Sub GetPhotoone()
Dim myPict As Picture
Dim myPictName As String
Dim rng As Range
Set rng = ActiveCell
myPictName = rng
With ActiveSheet
With .Range("AA1:AA50")
If IsEmpty(ActiveCell) Then Exit Sub
On Error Resume Next
If IsEmpty(ActiveCell.Offset(-1, 0)) Then Set TopCell = ActiveCell Else
Set TopCell = ActiveCell.End(xlUp)
If IsEmpty(ActiveCell.Offset(1, 0)) Then Set BottomCell = ActiveCell
Else Set BottomCell = ActiveCell.End(xlDown)
Range(TopCell, BottomCell).Select
Set myPict = .Parent.Pictures.Insert(filename:=myPictName)
myPict.Top = rng.Top
myPict.Left = rng.Left
myPict.Width = rng.Width
myPict.Height = rng.Height
myPict.Name = "Pict_" & .Cells(1).Address(0, 0)
End With
End With
End Sub
=============
many thanks
Abdul Kader
I have below code it's to insert photo in the cell and adjust the size
automatically as the row and Colum width and height, it's working perfect in
excel 2003, but in excel 2007 not working as I need, now only inserting the
photo without adjust it automatically .
Can anyone help me to modify the code to work in excel 2007
=============
Sub GetPhotoone()
Dim myPict As Picture
Dim myPictName As String
Dim rng As Range
Set rng = ActiveCell
myPictName = rng
With ActiveSheet
With .Range("AA1:AA50")
If IsEmpty(ActiveCell) Then Exit Sub
On Error Resume Next
If IsEmpty(ActiveCell.Offset(-1, 0)) Then Set TopCell = ActiveCell Else
Set TopCell = ActiveCell.End(xlUp)
If IsEmpty(ActiveCell.Offset(1, 0)) Then Set BottomCell = ActiveCell
Else Set BottomCell = ActiveCell.End(xlDown)
Range(TopCell, BottomCell).Select
Set myPict = .Parent.Pictures.Insert(filename:=myPictName)
myPict.Top = rng.Top
myPict.Left = rng.Left
myPict.Width = rng.Width
myPict.Height = rng.Height
myPict.Name = "Pict_" & .Cells(1).Address(0, 0)
End With
End With
End Sub
=============
many thanks
Abdul Kader