+ Reply to Thread
Results 1 to 7 of 7

Vba to get the coordinates of the shapes

Hybrid View

  1. #1
    Registered User
    Join Date
    03-08-2025
    Location
    KSA
    MS-Off Ver
    365
    Posts
    28

    Vba to get the coordinates of the shapes

    HI EVERYONE

    I am not sure if excel can do this but maybe experts know.

    I need the excel worksheet to automate and check the coordinates of the shapes (x and y) from its center whenever you move across the sheet or add new shapes.

    Attached sample.


    Hope somebody can dot his. Thank you.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    01-25-2011
    Location
    Belgium, Alveringem
    MS-Off Ver
    Excel 2003, 2007, 365
    Posts
    1,446

    Re: Vba to get the coordinates of the shapes

    hello,
    Sub coord()
         Dim i, N, Arr
         With Sheets("Sheet1")
              N = .Shapes.Count
              ReDim Arr(1 To N, 1 To 8)
              For i = 1 To N
                   With .Shapes(i)
                        Arr(i, 1) = .Name
                        Arr(i, 2) = .Left
                        Arr(i, 3) = .Top
                        Arr(i, 4) = .Width
                        Arr(i, 5) = .Height
                        Arr(i, 6) = .Rotation
                        Arr(i, 7) = Arr(i, 2) + Arr(i, 4) / 2
                        Arr(i, 8) = Arr(i, 3) + Arr(i, 5) / 2
                   End With
              Next
              
              With .Range("AQ1")
                   .Resize(, 8).Value = Split("Name, left Top Width Height Rotaton CenterX CenterY")
                   .Offset(1).Resize(UBound(Arr), UBound(Arr, 2)).Value = Arr
              End With
         End With
    End Sub
    Attached Files Attached Files
    Remember, saying thanks only takes a second or two. Click the little star * below, to give some Rep if you think an answer deserves it.

  3. #3
    Registered User
    Join Date
    03-08-2025
    Location
    KSA
    MS-Off Ver
    365
    Posts
    28

    Re: Vba to get the coordinates of the shapes

    Thank you bsalv that was great..question..where are the values reference from? like height and width? Thanks buddy

  4. #4
    Forum Expert
    Join Date
    01-25-2011
    Location
    Belgium, Alveringem
    MS-Off Ver
    Excel 2003, 2007, 365
    Posts
    1,446

    Re: Vba to get the coordinates of the shapes

    you asked the centerX and Y, so you have to calculate them with the values top, left, width and height :
    * CenterX=left + 0.5 * Width
    * CenterY = top + 0.5 * Height

  5. #5
    Registered User
    Join Date
    03-08-2025
    Location
    KSA
    MS-Off Ver
    365
    Posts
    28

    Re: Vba to get the coordinates of the shapes

    Copy that bsalv. Is it possible to correspond the position of the shape to the grid like sample the location of shape named 1 on the attached image is 8 horizontal and 4 vertical, the reference is the center of the shape?
    Attached Images Attached Images

  6. #6
    Forum Expert
    Join Date
    01-25-2011
    Location
    Belgium, Alveringem
    MS-Off Ver
    Excel 2003, 2007, 365
    Posts
    1,446

    Re: Vba to get the coordinates of the shapes

    an update with that centercell
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    03-08-2025
    Location
    KSA
    MS-Off Ver
    365
    Posts
    28

    Re: Vba to get the coordinates of the shapes

    Thank you so much bsalv. its working now. I can start from this.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Generate random coordinates in an area given (i,j) coordinates with VBA
    By tugbina in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-12-2023, 12:54 AM
  2. Bind cell to shapes and be able to adjust printing coordinates
    By desantech in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-01-2018, 04:10 AM
  3. Shapes With Coordinates Overlap
    By ahmedmd in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 05-15-2017, 04:02 PM
  4. excel 2013 customize context shapes and shapes group menu right click
    By Giuseppe77 in forum Hello..Introduce yourself
    Replies: 1
    Last Post: 12-03-2016, 11:50 AM
  5. Calling All Gurus! Need to output coordinates of shapes into a list
    By Scott_Dreppan in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-21-2015, 01:07 AM
  6. How To Move Shapes From Another Shapes? (floating shapes)
    By MarcLev in forum Word Programming / VBA / Macros
    Replies: 2
    Last Post: 10-04-2009, 04:04 PM
  7. [SOLVED] Convert point coordinates -> pixel coordinates
    By Zorro in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-31-2006, 10:30 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1