BuildFreeform co-ordinates

CraigM

Active Member
Joined
Feb 27, 2003
Messages
320
This has got me tearing my hair out.
Can anybody tell me why the following code works fine:

With ActiveSheet.Shapes.BuildFreeform(msoEditingAuto, 145, 9.75)
.AddNodes msoSegmentLine, msoEditingAuto, 137.25, 9.75
.AddNodes msoSegmentLine, msoEditingAuto, 145, 19.75
.AddNodes msoSegmentLine, msoEditingAuto, 145, 9.75
.AddNodes msoSegmentLine, msoEditingAuto, 145, 9.75
.ConvertToShape.Select
End With

But this code:

With ActiveSheet.Shapes.BuildFreeform(msoEditingAuto, 145, 9.75)
.AddNodes msoSegmentLine, msoEditingAuto, 140, 9.75
.AddNodes msoSegmentLine, msoEditingAuto, 145, 19.75
.AddNodes msoSegmentLine, msoEditingAuto, 145, 9.75
.AddNodes msoSegmentLine, msoEditingAuto, 145, 9.75
.ConvertToShape.Select
End With

Gives me a 1004 error on the .ConvertToShape.Select line? They are identical except for one number. Do the co-ordinates have to conform to a particular number type for .AddNodes? Any help would be great. I'm using Excel 2000.

Thanks, Craig
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Hi Craig,

I am surprised that either of them work, since both create a zero-length line segment (the last two AddNodes). Is this what you intend?

Damon
 
Upvote 0
Thanks Damon,

The first one definitely works. I've played around with creating these zero length lines to check that it worked, because the procedure I am writing draws shapes that sometimes have 3 sides and sometimes have 4. There is usually no problem with them.

But here is another example without a zero lenth line which also produces the same error:

With ActiveSheet.Shapes.BuildFreeform(msoEditingAuto, 456, 137.25)
.AddNodes msoSegmentLine, msoEditingAuto, 451, 137.25
.AddNodes msoSegmentLine, msoEditingAuto, 481, 197.25
.AddNodes msoSegmentLine, msoEditingAuto, 481, 187.25
.AddNodes msoSegmentLine, msoEditingAuto, 456, 137.25
.ConvertToShape.Select
End With

Craig
 
Upvote 0
That's interesting!

I'm using Excel 2000 (9.0 isn't it?), and Windows NT.
I've investigated it further, and (for me) it will only work properly if the co-ordinate in question (ie 137.25/140 in the first two example) is <=137.5 or >=152. Seems very strange to me.
 
Upvote 0
I'm guessing you haven't had any luck on this Juan?
Thanks for the effort anyway.
Craig
 
Upvote 0
Hi again Craig,

I was waiting to see if someone could come up with a solution before suggesting this workaround. Actually, I have had very similiar problems with a number of aspects of Shape objects in the past, and am convinced that they are very "buggy". My proposal would be to go back to the archaic--but still working--Drawing object of the past. I have had to revert to these a number of times to get around these problems. These are still supported in Excel 2000, but I don't know about continued support in later versions of Excel. Their documentation is hidden and you have to do an unhide on them to be able to view their help files. But here is an example of building a 'freeform' using Drawings:

Dim Poly As Object
Set Poly = ActiveSheet.Drawings.Add(145, 9.75, 140, 9.75, False)
Poly.AddVertex 145, 19.75
Poly.AddVertex 145, 9.75

etc.


Best of success.

Damon
 
Upvote 0
Thanks Damon, I was just about ready to give up on this! Your idea works perfectly, but I think I'll include both methods in my code, as it seems that the problem (I'm sure it is a bug) doesn't exist in XP. That way if it isn't supported in the future as you suggest, I should still have some functioning code.

Thanks for the tip - I never knew it even existed.
Craig
 
Upvote 0
Zombie Thread Rising! ... but since the author of Post #8 is still active:
The code in post #8 still runs in Excel 2010.
Could you expand on:
Their documentation is hidden and you have to do an unhide on them to be able to view their help files.
 
Upvote 0

Forum statistics

Threads
1,216,014
Messages
6,128,273
Members
449,436
Latest member
blaineSpartan

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top