Excel vba插入箭头macros

我在Excel中创build了一个macros,通过键盘命令插入一个红色的箭头。 我想通过研究如何使其停止select当我编写macros时select的单元格,但我不知道如何使它插入每次我当前select旁边的箭头。 它目前插入的箭头在我loggingmacros时的原始行相同的位置。 有没有解决的办法?

这里是代码:

Sub Red_Arrow_Insert() Red_Arrow_Insert Macro Insert Red Arrow Keyboard Shortcut: Ctrl+Shift+A ActiveCell.Select ActiveSheet.Shapes.AddConnector(msoConnectorStraight, 264, 50.25, 353.25, 139.5 _ ).Select Selection.ShapeRange.Line.EndArrowheadStyle = msoArrowheadOpen With Selection.ShapeRange.Line .Visible = msoTrue .ForeColor.RGB = RGB(255, 0, 0) .Transparency = 0 End With With Selection.ShapeRange.Line .Visible = msoTrue .Weight = 1.5 End With ActiveCell.Select End Sub 

这个请求可以通过使用ActiveCellTopLeft属性来完成,并使用这些数字来放置箭头,因为TopLeft属性相对于文档的左上angular进行测量,并且假定箭头将始终是静态长度。

请参阅下面的重构代码:

 Sub Red_Arrow_Insert() 'Red_Arrow_Insert Macro 'Insert Red Arrow 'Keyboard Shortcut: Ctrl Shift + A Dim l As Long, t As Long l = ActiveCell.Left t = ActiveCell.Top ActiveSheet.Shapes.AddConnector(msoConnectorStraight, t + 89.25, l + 89.25, l, t).Select With Selection With .ShapeRange.Line .EndArrowheadStyle = msoArrowheadOpen .Visible = msoTrue .ForeColor.RGB = RGB(255, 0, 0) .Transparency = 0 .Weight = 1.5 End With End With ActiveCell.Select 'assumes you want to activate the last active cell. End Sub 

NB – 我用89.25作为长度,因为它是在你的原始代码点的差异。 根据需要更改。