Picture number

  • Thread starter Thread starter Bobby
  • Start date Start date
B

Bobby

How can I know the picture number in a specific cell? I would like to
pass the info to the
ActiveSheet.Shapes("Picture xx").Select
Thank's ahead
 
The pictures actually float over the cells. But you could use something like:

Dim myCell as range
dim myPict as picture
dim FoundIt as boolean

with activesheet
set mycell = .range("c9") 'or something
for each myPict in .pictures
if mypict.topleftcell.address = mycell.address then
foundit = true
exit for
end if
next mypict
end with

if foundit = true then
mypict.select
else
msgbox "No pictures found!"
end if
 
Thank's Dave,
When I try the macro I get a mismatch error on

For Each myPict In .Pictures
Any clue?
Thank's ahead
 
Did you change other stuff in the code?

Do you still have this line:
dim myPict as Picture
 
Dave I did not change anything and yes I still have
dim myPict as Picture
 
Post your code. I don't see anything that jumps out. (It worked ok for me,
too.)
Dave I did not change anything and yes I still have
dim myPict as Picture
 
OK this is it:
At the time that I run this macro the cell cursor has a picture in it
at Range("D12")
Sub Macro4()
'
' Macro4 Macro
'
Dim myCell As Range
Dim myPict As Picture
Dim FoundIt As Boolean


With ActiveSheet
Set myCell = .Range("D12") 'or something
For Each myPict In .Pictures
If myPict.TopLeftCell.Address = myCell.Address Then
FoundIt = True
Exit For
End If
Next myPict
End With


If FoundIt = True Then
myPict.Select
Else
MsgBox "No pictures found!"
End If

End Sub
 
I still don't get a mismatch error when I try the code.
OK this is it:
At the time that I run this macro the cell cursor has a picture in it
at Range("D12")
Sub Macro4()
'
' Macro4 Macro
'
Dim myCell As Range
Dim myPict As Picture
Dim FoundIt As Boolean

With ActiveSheet
Set myCell = .Range("D12") 'or something
For Each myPict In .Pictures
If myPict.TopLeftCell.Address = myCell.Address Then
FoundIt = True
Exit For
End If
Next myPict
End With

If FoundIt = True Then
myPict.Select
Else
MsgBox "No pictures found!"
End If

End Sub
 
I don't have a guess why it's not working for you--do you have other shapes in
that activesheet that might confuse excel?

Maybe going through the shapes collection would work better:

Option Explicit

Sub Macro4()
'
' Macro4 Macro
'
Dim myCell As Range
Dim myShape As Shape
Dim FoundIt As Boolean


With ActiveSheet
Set myCell = .Range("D12") 'or something
For Each myShape In .Shapes
If myShape.TopLeftCell.Address = myCell.Address Then
FoundIt = True
Exit For
End If
Next myShape
End With


If FoundIt = True Then
myShape.Select
Else
MsgBox "No pictures found!"
End If

End Sub

OK this is it:
At the time that I run this macro the cell cursor has a picture in it
at Range("D12")
Sub Macro4()
'
' Macro4 Macro
'
Dim myCell As Range
Dim myPict As Picture
Dim FoundIt As Boolean

With ActiveSheet
Set myCell = .Range("D12") 'or something
For Each myPict In .Pictures
If myPict.TopLeftCell.Address = myCell.Address Then
FoundIt = True
Exit For
End If
Next myPict
End With

If FoundIt = True Then
myPict.Select
Else
MsgBox "No pictures found!"
End If

End Sub
 
Could it be the Excel version that I use?(Excel 2003 (11.8012.6568)
SP2
-
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top