Reputation: 42
I have a question regarding accessing a shape in visio 2003
...
dim ovp as visio.page
dim ovs as visio.shape
...
set ovs = ovp.shapes("#shapename#")
...do something with the shape
This sometimes does not work!
It gives an error like shape not found
or similar
...
dim ovp as visio.page
dim ovs as visio.shape
...
for each ovs in ovp.shapes
if ovs.name = "#shapename#" then
...do something with the shape
end if
next
This always works. Any idea why?
Upvotes: 0
Views: 291
Reputation: 71
Where are you getting #shapename# from? As a test, inside the foreach ovs, put a debug.print ovs.name to see what names you are dealing with in that collection.
Upvotes: 0
Reputation: 26259
Here's a possibility:
When you do set ovs = ovp.shapes("#shapename#")
, VBA is looking for an exact match for the shape name, in a case-sensitive manner.
When you do if ovs.name = "#shapename#"
and if you have Option Compare Text
defined in your module, then it will do a case-insensitive comparison.
So, in that particular situation, you may get the results you describe if both of the following are true:
Option Compare Text
"#ShapeName#"
but you are searching for "#shapename#"
.Can you comment to clarify if any of this might apply?
Upvotes: 1