找回密码
 注册会员
查看: 355|回复: 9

[作品展示] excel 自制指示器

[复制链接]
发表于 2022-7-7 09:24:31 |Error| 显示全部楼层 |阅读模式

我们不再是孤独的探索者;让我们的手紧紧相连,一起成长。

您需要 登录 才可以下载或查看,没有账号?注册会员

×
本帖最后由 自贡黄明儒 于 2022-7-7 09:25 编辑

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
   Call MsoLineRun(Sh, Target)
End Sub

'''增加一个虚箭头
Function AddMsoLine(ByVal s As String, ByVal Sh As Object) As Object
    Set AddMsoLine = Sh.Shapes.AddConnector(msoConnectorStraight, 0, 0, 100, 50)
    With AddMsoLine.Line
        .EndArrowheadStyle = msoArrowheadOpen
        .Visible = msoTrue
        .DashStyle = msoLineDashDot
        .ForeColor.RGB = RGB(255, 0, 0)
        .Weight = 0
        .Parent.AlternativeText = s
        .Parent.Name = s
    End With
End Function
''判断虚箭头是否存在,不存在则添加
Function MsoLineExist(ByVal s As String, ByVal Sh As Object) As Object
    For Each X In Sh.Shapes
        If X.Name = s And X.AlternativeText = s Then Set MsoLineExist = X: Exit For
    Next
End Function

'''小平箭头Hor1,竖直箭头Ver1
Sub MsoLineRun(ByVal Sh As Object, ByVal Target As Range)
    Dim obj As Object
    Dim Left1&, Top1&, Column1&, Row1&
    Application.ScreenUpdating = False
    Application.EnableEvents = False
   
    If Target.Rows.Count = 1 And Target.Columns.Count = 1 Then
    Application.ScreenUpdating = False
    Application.ScreenUpdating = True
        With ActiveCell
            Left1 = .Left
            Top1 = .Top
            Column1 = .Column
            Row1 = .Row
        End With
        Set obj = MsoLineExist("Hor1", Sh)
        If obj Is Nothing Then Set obj = AddMsoLine("Hor1", Sh)
        With obj
            .Left = Left1 + ActiveCell.Width * 0.5
            .Top = Sh.Cells(1, Column1).Top
            .Width = 0
            .Height = Top1
        End With
        Set obj = MsoLineExist("Ver1", Sh)
        If obj Is Nothing Then Set obj = AddMsoLine("Ver1", Sh)
        With obj
            .Left = Sh.Cells(Row1, 1).Left
            .Top = Top1 + ActiveCell.Height * 0.25
            .Width = Left1
            .Height = 0
        End With
    End If
    Application.EnableEvents = True
    Application.ScreenUpdating = True
End Sub
'''箭头删除
Sub KillMsoLine()
    Application.ScreenUpdating = False
    Application.EnableEvents = False
    For Each X In ActiveSheet.Shapes
        If X.Type = msoAutoShape Then
            If InStr(X.Name, "Hor") > 0 Or InStr(X.Name, "Ver") > 0 Then X.Delete
        End If
    Next
    Application.EnableEvents = True
    Application.ScreenUpdating = True
End Sub
1.gif
 楼主| 发表于 2022-7-7 09:36:57 |Error| 显示全部楼层
以上是完整代码,贴入excel就可运行。
回复 顶 踩

使用道具 举报

发表于 2022-7-7 11:04:22 |Error| 显示全部楼层
谢谢楼主分享。
回复 顶 踩

使用道具 举报

发表于 2022-7-10 20:09:06 |Error| 显示全部楼层
谢谢楼主分享
回复 顶 踩

使用道具 举报

发表于 2022-7-11 08:07:52 |Error| 显示全部楼层

谢谢楼主分享。
回复 顶 踩

使用道具 举报

发表于 2022-7-11 16:35:21 |Error| 显示全部楼层
楼主已经把表格玩转了
回复 顶 踩

使用道具 举报

发表于 2022-7-12 13:44:30 |Error| 显示全部楼层
楼主:
   你不发个怎样加载,我们才会用呢。
回复 顶 踩

使用道具 举报

发表于 2022-7-12 17:03:36 |Error| 显示全部楼层
自贡黄明儒 发表于 2022-7-7 09:36
以上是完整代码,贴入excel就可运行。

怎么贴,试了粘贴不能用
回复 顶 踩

使用道具 举报

 楼主| 发表于 2022-7-13 07:30:05 |Error| 显示全部楼层
joyb 发表于 2022-7-12 17:03
怎么贴,试了粘贴不能用

只能帮你到这一步了
QQ图片20220713072530.png
回复 顶 踩

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

小黑屋|手机版|Cncad.Net ( 苏ICP备2026083443号 )

GMT+8, 2026-11-1 19:30 , Processed in 0.270736 second(s), 26 queries .

Powered by Discuz! X5.0

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表