Hello,
i have a nice hex grid shapefile of the United Kingdom.
Is there a way to get the x/y coordinates of all centers of the shapes?
Please see the example file, there are 12 Shape(groups) in it.
kind regards,
Stefan
Get the x/y coordinates oft the center of shapes
-
- 4StarLounger
- Posts: 415
- Joined: 29 Mar 2010, 11:50
- Location: Vienna, Austria
Get the x/y coordinates oft the center of shapes
You do not have the required permissions to view the files attached to this post.
-
- 4StarLounger
- Posts: 587
- Joined: 14 Nov 2012, 16:06
Re: Get the x/y coordinates oft the center of shapes
Code: Select all
Sub M_snb()
For Each it In Sheet1.Shapes
MsgBox "y=: " & it.Top + it.Height / 2 & vbLf & "x=: " & it.Left + it.Width / 2, , it.Name
Next
End Sub
-
- 4StarLounger
- Posts: 415
- Joined: 29 Mar 2010, 11:50
- Location: Vienna, Austria
Re: Get the x/y coordinates oft the center of shapes
thanks, but how shall i go through it, if the variables are not declared?
-
- 4StarLounger
- Posts: 587
- Joined: 14 Nov 2012, 16:06
Re: Get the x/y coordinates oft the center of shapes
Remove 'Option Explicit'
-
- Administrator
- Posts: 78591
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Get the x/y coordinates oft the center of shapes
Or declare
Dim it As Shape
and replace Sheet1 with the codename of the sheet, or with Active sheet.
Dim it As Shape
and replace Sheet1 with the codename of the sheet, or with Active sheet.
Best wishes,
Hans
Hans
-
- 4StarLounger
- Posts: 563
- Joined: 27 Jun 2021, 10:46
Re: Get the x/y coordinates oft the center of shapes
>Remove 'Option Explicit'
Not sure I'd ever advise that
Not sure I'd ever advise that
-
- Administrator
- Posts: 78591
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Get the x/y coordinates oft the center of shapes
snb NEVER declares any local variable...
Best wishes,
Hans
Hans
-
- 4StarLounger
- Posts: 587
- Joined: 14 Nov 2012, 16:06
Re: Get the x/y coordinates oft the center of shapes
Snb only declares private & public variables and tries to avoid those as much as possible. (see www.snb-vba.eu)
Declaring Local variables is 100% redundant.
So the use of 'NEVER' and 'any' is incorrect and should be replaced by 'Only if necessary'.
Declaring Local variables is 100% redundant.
So the use of 'NEVER' and 'any' is incorrect and should be replaced by 'Only if necessary'.
-
- Administrator
- Posts: 78591
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Get the x/y coordinates oft the center of shapes
I have edited my previous reply to "any local variable". I strongly disagree with your statement "Declaring Local variables is 100% redundant."
Best wishes,
Hans
Hans
-
- 4StarLounger
- Posts: 415
- Joined: 29 Mar 2010, 11:50
- Location: Vienna, Austria
Re: Get the x/y coordinates oft the center of shapes
sorry, that i started a debate over declaring variables, i only wanted to get the x / y of shape coordinates into columns C and D and i know the diferences, but as i am not very good in using VBA i declare as often as i could.
thanks anyway.
thanks anyway.
-
- Administrator
- Posts: 78591
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Get the x/y coordinates oft the center of shapes
See the attached workbook.
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans
Hans
-
- 4StarLounger
- Posts: 415
- Joined: 29 Mar 2010, 11:50
- Location: Vienna, Austria
Re: Get the x/y coordinates oft the center of shapes
Thank You, Hans!