Change a Visio Shape’s Pin to the Top-Left with VBA
Question details
Set a Visio shape’s local pin position to its top-left corner using VBA.

- Product
- Microsoft Visio
- Device & OS
- not provided
- Scenario
- The user wants to control a shape’s pin position through its ShapeSheet formulas.
- Observed behavior
- The desired local pin position is at the top-left of the shape, with LocPinX set to zero and LocPinY set to the shape’s height.
Open the drawing in Visio and select the shape whose pin you want to change. Enable the Developer tab if needed, and make sure your Visio installation allows you to run trusted VBA macros.
Set the Selected Shape’s Local Pin with VBA
Use ShapeSheet formulas to place the selected shape’s local pin at its top-left corner.
Visio’s local shape coordinates run from left to right and bottom to top. LocPinX = Width*0 and LocPinY = Height*1 therefore identify the top-left corner in the shape’s local coordinate system.
Changing the local pin can also change the shape’s position on the page because PinX and PinY control the pin’s page position.
In the Visio drawing window, click the shape you want to modify.
Choose Developer > Visual Basic, then insert a module in the drawing’s VBA project.
Paste this code into the module: Sub SetPinTopLeft() Dim shp As Visio.Shape Set shp = ActiveWindow.Selection.Item(1) shp.CellsU("LocPinX").FormulaU = "Width*0" shp.CellsU("LocPinY").FormulaU = "Height*1" End Sub
With the shape still selected, run SetPinTopLeft from the VBA editor or Developer > Macros. Check the result in View > Task Panes > Size & Position.

Record a Pin Position Change When the Macro Recorder Is Available
Use a recorded action as a starting point if your Visio edition includes a macro recorder.
Use WPS Office for Everyday Office Documents
WPS Office is a free, lightweight Office alternative with a familiar interface and support for common Microsoft Office formats, making it easy to move everyday documents between suites. It does not change Visio ShapeSheet pins or run this Visio VBA macro.

Frequently Asked Questions
Which ShapeSheet cells control a shape’s local pin?
LocPinX and LocPinY define the pin’s position in the shape’s local coordinate system. Set them through VBA with shp.CellsU("LocPinX").FormulaU and shp.CellsU("LocPinY").FormulaU.
Why might the shape move when I change its local pin?
PinX and PinY specify the pin’s position on the page. Changing LocPinX or LocPinY while those page coordinates remain fixed can shift the shape relative to the page.
Can I put the pin at the center instead?
Yes. Set LocPinX to Width*0.5 and LocPinY to Height*0.5 in the ShapeSheet or in the VBA macro.
What if I cannot find the macro recorder in Visio?
Recorder availability varies by Visio installation. You can still open Developer > Visual Basic and enter the provided macro manually if VBA is available.




