Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Qestion to judge whether the candidate has passed or failed ...... | New Users to Excel | |||
Formatting worksheets, existing and new, in existing workbooks | Excel Discussion (Misc queries) | |||
determine wheter string has a number in it? | Excel Worksheet Functions | |||
how do I judge current document is a blank one? | Excel Programming | |||
Get an object representing an existing Excel instance from Outlook | Excel Programming |