Discussion:
請問如何以VBA語法得知儲存格中是否有設定超聯結?
(时间太久无法回复)
unknown
2009-04-22 04:31:01 UTC
Permalink
原語法如下,現在想加上判定,請問該用什麼語法?

Sub 清除超聯結()

清除欄數 = InputBox("清除欄數:", , 1)
清除列數 = InputBox("清除列數:", , 1)

If I <> "" And J <> "" Then

For I = 1 To 清除欄數
For J = 1 To 清除列數

Cells(J, I).Hyperlinks.Delete

Next J
Next I

MsgBox ("超聯結清除完成")

End If

End Sub
--
~_~a...
天道無常
2009-04-23 00:58:02 UTC
Permalink
if ActiveCell.Hyperlinks.Count <> 0
Post by unknown
原語法如下,現在想加上判定,請問該用什麼語法?
Sub 清除超聯結()
清除欄數 = InputBox("清除欄數:", , 1)
清除列數 = InputBox("清除列數:", , 1)
If I <> "" And J <> "" Then
For I = 1 To 清除欄數
For J = 1 To 清除列數
Cells(J, I).Hyperlinks.Delete
Next J
Next I
MsgBox ("超聯結清除完成")
End If
End Sub
unknown
2009-04-23 06:59:02 UTC
Permalink
"天道無常" 來函:
Post by 天道無常
if ActiveCell.Hyperlinks.Count <> 0
感謝大大的提點...小弟感激不盡

嗯...現將修改後的碼舖上來,僅供有同類問題的人參考

Attribute VB_Name = "清除謎之超聯結"
Sub 清除謎之超聯結()

清除欄數 = InputBox("清除欄數:", "左右為欄", 0)
清除列數 = InputBox("清除列數:", "上下為列", 0)

If 清除列數 <> 0 And 清除欄數 <> 0 Then

For I = 1 To 清除列數
For J = 1 To 清除欄數
'MsgBox (I & "." & J & ":" & Cells(I, J).Hyperlinks.Count)
If Cells(I, J).Hyperlinks.Count <> 0 Then

A01 = Cells(I, J).Interior.ColorIndex
A02 = Cells(I, J).Font.Name
A03 = Cells(I, J).Font.FontStyle
A04 = Cells(I, J).Font.Size
A05 = Cells(I, J).Font.Strikethrough
A06 = Cells(I, J).Font.Superscript
A07 = Cells(I, J).Font.Subscript
A08 = Cells(I, J).Font.OutlineFont
A09 = Cells(I, J).Font.Shadow
A10 = Cells(I, J).Font.Underline
A11 = Cells(I, J).Font.ColorIndex

B01 = Cells(I, J).Borders(xlEdgeLeft).LineStyle
B02 = Cells(I, J).Borders(xlEdgeLeft).Weight
B03 = Cells(I, J).Borders(xlEdgeLeft).ColorIndex

B04 = Cells(I, J).Borders(xlEdgeTop).LineStyle
B05 = Cells(I, J).Borders(xlEdgeTop).Weight
B06 = Cells(I, J).Borders(xlEdgeTop).ColorIndex

B07 = Cells(I, J).Borders(xlEdgeBottom).LineStyle
B08 = Cells(I, J).Borders(xlEdgeBottom).Weight
B09 = Cells(I, J).Borders(xlEdgeBottom).ColorIndex

B10 = Cells(I, J).Borders(xlEdgeRight).LineStyle
B11 = Cells(I, J).Borders(xlEdgeRight).Weight
B12 = Cells(I, J).Borders(xlEdgeRight).ColorIndex

Cells(I, J).Hyperlinks.Delete

Cells(I, J).Interior.ColorIndex = A01
Cells(I, J).Font.Name = A02
Cells(I, J).Font.FontStyle = A03
Cells(I, J).Font.Size = A04
Cells(I, J).Font.Strikethrough = A05
Cells(I, J).Font.Superscript = A06
Cells(I, J).Font.Subscript = A07
Cells(I, J).Font.OutlineFont = A08
Cells(I, J).Font.Shadow = A09
Cells(I, J).Font.Underline = A10
Cells(I, J).Font.ColorIndex = A11

Cells(I, J).Borders(xlEdgeLeft).LineStyle = B01
Cells(I, J).Borders(xlEdgeLeft).Weight = B02
Cells(I, J).Borders(xlEdgeLeft).ColorIndex = B03

Cells(I, J).Borders(xlEdgeTop).LineStyle = B04
Cells(I, J).Borders(xlEdgeTop).Weight = B05
Cells(I, J).Borders(xlEdgeTop).ColorIndex = B06

Cells(I, J).Borders(xlEdgeBottom).LineStyle = B07
Cells(I, J).Borders(xlEdgeBottom).Weight = B08
Cells(I, J).Borders(xlEdgeBottom).ColorIndex = B09

Cells(I, J).Borders(xlEdgeRight).LineStyle = B10
Cells(I, J).Borders(xlEdgeRight).Weight = B11
Cells(I, J).Borders(xlEdgeRight).ColorIndex = B12

End If
Next J
Next I

MsgBox ("「謎之超聯結」與「不是謎之超聯結」都清除掉了...")

End If

End Sub

Loading...