Sub BreakLinks()
Dim wb As Workbook
Set wb = Application.ActiveWorkbook
If Not IsEmpty(wb.LinkSources(xlExcelLinks)) Then
For Each link In wb.LinkSources(xlExcelLinks)
wb.BreakLink link, xlLinkTypeExcelLinks
Next link
End If
End Sub
此代码会破坏事件工作簿的所有外部链接。如何为特定工作表中的选定范围执行此操作?
另外,我想首先在列表中显示外部链接(从选定的范围内),然后显示 2 个按钮:1 删除它们,2 取消。
任何帮助,将不胜感激。
最佳答案
LinkSources(xlExcelLinks)
是 Workbook
的一种方法- MSDN Workbook.LinkSources ,因此不提供 .BreakLink
到细胞。
但是,您可以使用给定范围 (givenRange.SpecialCells(xlCellTypeFormulas)
) 中的公式遍历单元格并检查它们是否包含 [
,这是链接公式所必需的。如果他们有,只需将公式写为值:
Option Explicit
Sub BreakLinks()
Dim givenRange As Range
Set givenRange = Selection
Dim myCell As Range
For Each myCell In givenRange.SpecialCells(xlCellTypeFormulas)
If InStr(myCell.Formula, "[") Then
Debug.Print myCell.Address
myCell.Value2 = myCell.Value2
End If
Next myCell
End Sub
关于vba - 仅为工作表中的特定范围断开外部链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50797640/