Others

Change a Visio Shape’s Pin to the Top-Left with VBA

Bushra ParveenBushra Parveen Nov 20, 2026 868 views

Question details

Set a Visio shape’s local pin position to its top-left corner using VBA.

Change a Visio Shape’s Pin Position to the Top-Left with 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.
Before you start

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.

Solution 1Recommended

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.

1
Select the shape

In the Visio drawing window, click the shape you want to modify.

2
Open the VBA editor

Choose Developer > Visual Basic, then insert a module in the drawing’s VBA project.

3
Add the macro

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

4
Run and check the macro

With the shape still selected, run SetPinTopLeft from the VBA editor or Developer > Macros. Check the result in View > Task Panes > Size & Position.

Set the Selected Shape’s Local Pin with VBA
Use another pin position: For a center pin, use Width*0.5 and Height*0.5. For a bottom-right pin, use Width*1 and Height*0. Choose other proportions for a custom local position.
Free Microsoft Office alternative

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.

Work with documents, spreadsheets, and presentations in one familiar suiteOpen and edit Microsoft Word, Excel, and PowerPoint formats, including DOCX, XLSX, and PPTXKeep related project documents accessible while managing Visio diagrams separatelyUse a lightweight alternative for everyday Office tasks
QA img-9

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.