我需要在VB Excel中围绕它的终点旋转一条水平线。我尝试了在互联网上找到的各种解决方案,但效果不太好。
我给你们一些关于我想要做的事情的图片:
这是我的台词:
A点(72;378)
B点(165;378)

我想旋转点A,关于点B,旋转的角度是可变的。例如,这是一个60度的旋转

字母A和B是在截图后加上图片编辑的。
发布于 2018-10-21 12:53:52
尝尝这个。
Sub test()
Dim x As Single, y As Single
Dim nx As Single, ny As Single, l As Single
Dim i As Single, ra As Single
Dim Ws As Worksheet
Dim shp As Shape
Set Ws = ActiveSheet
For Each shp In Ws.Shapes
If shp.Type = msoLine Then
shp.Delete
End If
Next
x = 165
y = 378
l = 165 - 72
For i = 90 To 150
ra = WorksheetFunction.Radians(i)
nx = x - Sin(ra) * l
ny = y + Cos(ra) * l
Set shp = Ws.Shapes.AddLine(x, y, nx, ny)
With shp
.Line.EndArrowheadStyle = msoArrowheadTriangle
.Line.ForeColor.RGB = RGB(255, 0, 0)
.Line.Weight = 2
End With
DoEvents
Application.Wait Now + (TimeSerial(0, 0, 1) / 2)
shp.Delete
Next i
Set shp = Ws.Shapes.AddLine(x, y, nx, ny)
With shp
.Line.EndArrowheadStyle = msoArrowheadTriangle
.Line.ForeColor.RGB = RGB(255, 0, 0)
.Line.Weight = 2
End With
End Subhttps://stackoverflow.com/questions/52908312
复制相似问题