日常工作中VBA代码积累

 

1、超链接地址提取

 

 

Function GetURL(rng As Range) As String
    On Error Resume Next
    GetURL = rng.Hyperlinks(1).Address
End Function

 

2、表格多sheet页的目录跳转制作    (代码走查表为例)

(1)针对整个工作簿,即 ThisWorkbook,输入以下代码。

Sub 超链接()
Dim ct As Long
Sheet5.Rows("2:100000").ClearContents
For ct = 1 To Sheets.Count If Sheets(ct).Name <> "目录" And Sheets(ct).Name <> "代码问题" Then Sheet5.Range("a100000").End(xlUp).Offset(1, 0) = Sheets(ct).Name Sheet5.Hyperlinks.Add Anchor:=Sheet5.Range("a100000").End(xlUp), Address:="", SubAddress:="'" & Sheets(ct).Name & "'!A1" End If Next End Sub

(2)制作宏,并赋在相应按钮中,进行点击刷新。

Sub 宏1()
'
' 宏1 宏
'

'
    Range("A5").Select Selection.Hyperlinks(1).SubAddress = "'0711-0717'!A1" End Sub

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

你可能感兴趣的:(日常工作中VBA代码积累)