激活/停用超链接

时间:2018-08-15 10:29:01

标签: excel vba excel-vba

这是我第一次问一个问题,如果我没有提供足够的信息或以其他方式弄乱了我,我向所有人道歉!

我有一个带有隐藏区域的工作表,直到用户需要为止。创建一个新工作簿时,需要使用一个按钮和另一个按钮来再次隐藏它们。每个隐藏区域在一个文本框中包含一个超链接(这些超链接将用户带到工作簿中的其他工作表)(这样,当工作表受到保护时,该超级链接就可以工作)。我的问题是,超链接仍然处于活动状态,并且当这些超链接处于隐藏状态时,光标也会显示一个指针。当使用VBA或宏将超链接隐藏时,如何停用超链接?任何协助将非常欢迎。谢谢

工作表中的部分由代码隐藏/显示,该代码将颜色更改为与我不想关闭列或行的背景相同的颜色,因为我想保持工作表的标题和大小。

所有编码都可以完成我的工作,但是花了很长时间试图找到我的问题的答案,但是没有成功。隐藏部分最多可包含12个数据输入单元块,具体取决于用户项目需求而使用。

我下面放置的一部分代码用于显示第12块,然后下一个例程用于隐藏除数字1以外的所有块。下一个例程是我用于隐藏第2块文本框的子例程我决定从单元格中的超链接更改为文本框,以保护工作表,但仍将超链接用于仅查看目的。我已经添加了用于隐藏文本框的例程的代码,而这正是我正在尝试禁用超链接的代码。但是,我能找到的唯一看起来可以完成工作的代码是EnableEvents,但是我无法实现我想要的功能,所以就在这里。

我敢肯定,您会发现我注意到一个程序员,我借用了一些代码并将它们粘在一起并一起使用,直到它起作用为止,但是我已经花了很多时间来粘和玩。

Sub AppearCompOp12()
'
' AppearCompOp12 Macro
'

'
    Range("ar22:bd28").Select
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorLight1
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorDark1
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
    With Selection.Font
        .ThemeColor = xlThemeColorLight1
        .TintAndShade = 0
    End With
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .ColorIndex = xlAutomatic
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .ColorIndex = xlAutomatic
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .ColorIndex = xlAutomatic
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeRight)
        .LineStyle = xlContinuous
        .ColorIndex = xlAutomatic
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlInsideVertical)
        .LineStyle = xlContinuous
        .ColorIndex = xlAutomatic
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlInsideHorizontal)
        .LineStyle = xlContinuous
        .ColorIndex = xlAutomatic
        .TintAndShade = 0
        .Weight = xlThin
    End With
    Range("AR22").Select
    Selection.Font.Size = 16
    With Selection.Font
        .Color = -65536
        .TintAndShade = 0
    End With
End Sub

Sub ResetCapMSADashboard()
'
' ResetCapMSADashboard Macro
'

'
    Range( _
        "P6:AB12,AD6:AP12,AR6:BD12,AR14:BD20,AR22:BD28,AD14:AP20,AD22:AP28,P14:AB20,B14:N20,B22:N28,P22:AB28" _
        ).Select
    With Selection.Font
        .Color = RGB(217, 217, 217)
    End With
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorDark1
        .TintAndShade = -0.149998474074526
        .PatternTintAndShade = 0
    End With
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .ThemeColor = 1
        .TintAndShade = -0.14996795556505
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .ThemeColor = 1
        .TintAndShade = -0.14996795556505
        .Weight = xlThin
    End With
With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .ThemeColor = 1
        .TintAndShade = -0.14996795556505
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeRight)
        .LineStyle = xlContinuous
        .ThemeColor = 1
        .TintAndShade = -0.14996795556505
        .Weight = xlThin
    End With
    With Selection.Borders(xlInsideVertical)
        .LineStyle = xlContinuous
        .ThemeColor = 1
        .TintAndShade = -0.14996795556505
        .Weight = xlThin
    End With
    With Selection.Borders(xlInsideHorizontal)
        .LineStyle = xlContinuous
        .ThemeColor = 1
        .TintAndShade = -0.14996795556505
        .Weight = xlThin
    End With
    Range("BG2:BG26").Select
    Selection.ClearContents
    Range("J7").Select

End Sub

Sub RecolourTB2()
'
' Change text box & text to background colourbox

'
    ActiveSheet.Shapes.Range(Array("TextBox 9")).Select

    With Selection.ShapeRange.TextFrame2.TextRange.Font.Fill
        .Visible = msoTrue
        .ForeColor.ObjectThemeColor = msoThemeColorBackground1
        .ForeColor.TintAndShade = 0
        .ForeColor.Brightness = -0.25
        .Transparency = 0
        .Solid
    End With
    Range("P10:W10").Select
    ActiveSheet.Shapes.Range(Array("TextBox 9")).Select
    EnableEvents = False
    With Selection.ShapeRange.TextFrame2.TextRange.Font.Fill

        .Visible = msoTrue
        .ForeColor.ObjectThemeColor = msoThemeColorBackground1
        .ForeColor.TintAndShade = 0
        .ForeColor.Brightness = -0.150000006
        .Transparency = 0
        .Solid
    End With
    Range("P9:W9").Select
End Sub

0 个答案:

没有答案