Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default How to judge wheter an object is existing or not

I have a function which basically returns a found shape if succeed. But
what if nothing could be found and nothing is returned? How to judge
this in its calling code?

Function findShape(text as String)

if *** then
findShape = specifiedShape
end if
end function



sub doSth()
if findShape("special") then
msgbox "found"
end if
end sub

There always reports error on the line "if NOT findShape then", saying
that "Object does not support this property or method". Any
suggestions? Thanks,

lvcha

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default How to judge wheter an object is existing or not

Also, when no shape can be found, the line in doSth()

Set prevOval = findOval(TargetText)

results in "Object required" Run-time error.

How to fix that?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default How to judge wheter an object is existing or not

Function findShape(text as String) as Shape

On error Resume Next
if *** then
set findShape = specifiedShape
end if
On Error goto 0
end function

---------------------

Dim shp as Shape
On Error Resume Next
set shp = FindShape("shapename")
On Error goto 0

if not shp is nothing then
msgbox "found " & shp.Name
else
msgbox "Not found"
End if

--
Regards,
Tom Ogilvy


"lvcha.gouqizi" wrote in message
ups.com...
Also, when no shape can be found, the line in doSth()

Set prevOval = findOval(TargetText)

results in "Object required" Run-time error.

How to fix that?



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default How to judge wheter an object is existing or not

Thanks Tom very much!

I use shp = nothing in my original code so cannot get through each
time. My bad.

Can I ask more about Shape. What's the difference between Shape
Collection and Shape Object? If there is need to deal with shape
collection, should I use Null, Empty, or Nothing?

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default How to judge wheter an object is existing or not

The shape collection holds the list of all the shapes. It has a count
property, so to determine if there are no shapes

if activesheet.Shapes.count = 0 then
' there are no shapes.
else
for each shp in Activesheet.Shapes
msgbox shp.Name
Next
End if

--
Regards,
Tom Ogilvy


"lvcha.gouqizi" wrote in message
oups.com...
Thanks Tom very much!

I use shp = nothing in my original code so cannot get through each
time. My bad.

Can I ask more about Shape. What's the difference between Shape
Collection and Shape Object? If there is need to deal with shape
collection, should I use Null, Empty, or Nothing?





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default How to judge wheter an object is existing or not

I'd use something like:

Function findShape(myText as String) as Boolean
dim myShape as shape
set myshape = nothing
on error resume next
set myshape = activesheet.shapes(myText)
on error goto 0

if myshape is nothing then
findshape = false
else
findshape = true
end if

end function

or shorter:

Function findShape(myText as String) as Boolean
on error resume next
FindShape = CBool(Len(activesheet.shapes(myText).Name) 0)
on error goto 0
end function

"lvcha.gouqizi" wrote:

I have a function which basically returns a found shape if succeed. But
what if nothing could be found and nothing is returned? How to judge
this in its calling code?

Function findShape(text as String)

if *** then
findShape = specifiedShape
end if
end function

sub doSth()
if findShape("special") then
msgbox "found"
end if
end sub

There always reports error on the line "if NOT findShape then", saying
that "Object does not support this property or method". Any
suggestions? Thanks,

lvcha


--

Dave Peterson
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default How to judge wheter an object is existing or not

Thanks Dave. But if findShape() can find some shape, I would like to
get that Shape rather than just get the "True" value.

The problem is that when no shape can be found, the findShape() gets a
run-time error, and when some shape is found, the T/F judgement get an
error.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Qestion to judge whether the candidate has passed or failed ...... Neelakanta New Users to Excel 5 June 15th 08 03:02 PM
Formatting worksheets, existing and new, in existing workbooks G. Dagger[_2_] Excel Discussion (Misc queries) 4 January 7th 08 06:48 PM
determine wheter string has a number in it? Ted Metro Excel Worksheet Functions 5 June 2nd 07 04:18 AM
how do I judge current document is a blank one? Ronnie Excel Programming 4 August 2nd 05 02:21 PM
Get an object representing an existing Excel instance from Outlook R Avery Excel Programming 1 August 25th 04 11:16 PM


All times are GMT +1. The time now is 10:09 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"