Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Sub FindAndInsertPicture()
On Error Resume Next
Dim LookFor As String, ws As Worksheet
Dim p As Object, t As Double, l As Double, w As Double, h As Double
Dim PictureFileName As String, sAddress As String
LookFor = "text to find"
PictureFileName = "c:\examples\Other\insert.jpg"
For Each ws In Worksheets
sAddress = ws.Cells.Find(LookFor, , , , xlPart, False).Address
Do While sAddress <> ""
Set p = ActiveSheet.Pictures.Insert(PictureFileName)
With ws.Range(sAddress)
t = .Top
l = .Left
If CenterH Then
w = .Offset(0, 1).Left - .Left
l = l + w / 2 - p.Width / 2
If l < 1 Then l = 1
End If
If CenterV Then
h = .Offset(1, 0).Top - .Top
t = t + h / 2 - p.Height / 2
If t < 1 Then t = 1
End If
.Value = ""
End With
' position picture
With p
.Top = t
.Left = l
End With
sAddress = ws.Cells.Find(LookFor, , , xlPart, , xlNext, False).Address
Loop
Next
End Sub
Sub FindAndInsertPicture()
'On Error Resume Next
Dim LookFor As String, ws As Worksheet
Dim p As Object, t As Double, l As Double, w As Double, h As Double
Dim PictureFileName As String, sAddress As String
Dim c As Range
LookFor = "text to find"
PictureFileName = "c:\examples\Other\insert.jpg"
For Each ws In Worksheets
With ws
Set c = .Cells.Find(LookFor, , , , xlPart, False)
If Not c Is Nothing Then
sAddress = c.Address
Do
' Set p = ActiveSheet.Pictures.Insert(PictureFileName)
' With .Range(sAddress)
' t = .Top
' l = .Left
' If CenterH Then
' w = .Offset(0, 1).Left - .Left
' l = l + w / 2 - p.Width / 2
' If l < 1 Then l = 1
' End If
' If CenterV Then
' h = .Offset(1, 0).Top - .Top
' t = t + h / 2 - p.Height / 2
' If t < 1 Then t = 1
' End If
' .Value = ""
' End With
' ' position picture
' With p
' .Top = t
' .Left = l
' End With
Set c = .Cells.FindNext(c)
Loop While Not c Is Nothing And c.Address <> sAddress
End If
End With
Next
End Sub