我试图打破链接中包含关键字的所有链接。我不想打破每一个环节。我已经看过VBA必须是一个完整的文件名才能使它工作,但我想知道是否有办法打破只有关键词的所有链接?
例如,我下面有4个链接。我只想删除关键字"品牌网站预测"的链接,删除拥有它的3个链接。
每日品牌网站Flash.xlsx
品牌网站预测FY18(AUG).xlsx
品牌网站预测FY18(SEP).xlsx
品牌网站预测FY18(OCT).xlsx
我已经尝试了这个,但它不起作用:
ActiveWorkbook.BreakLink Name:="Brand Site Forecast", Type:=xlExcelLinks
但完整的文档名称是这样的:
ActiveWorkbook.BreakLink Name:="Brand Site Forecast FY18 (AUG).xlsx", Type:=xlExcelLinks
有什么想法吗?
答案 0 :(得分:1)
试试这个
Sub BreakExternalLinks()
Dim ExternalLinks As Variant
Dim wb As Workbook
Dim x As Long
Set wb = ActiveWorkbook
'Create an Array of all External Links stored in Workbook
ExternalLinks = wb.LinkSources(Type:=xlLinkTypeExcelLinks)
'Loop Through each External Link in ActiveWorkbook and Break it
For x = 1 To UBound(ExternalLinks)
'remove the links with the key words "Brand Site Forecast"
If InStr(1, ExternalLinks(x), "Brand Site Forecast", vbTextCompare) > 0 Then
wb.BreakLink Name:=ExternalLinks(x), Type:=xlLinkTypeExcelLinks
End If
Next x
End Sub
答案 1 :(得分:0)
感谢Maddy的帮助!我已经改变了一点VBA,现在它完美地工作了。这是VBA。
Sub BreakExternalLinks()
Dim ExternalLinks As Variant
Dim wb As Workbook
Dim x As Long
Set wb = ActiveWorkbook
'Create an Array of all External Links stored in Workbook
ExternalLinks = wb.LinkSources(Type:=xlLinkTypeExcelLinks)
'Loop Through each External Link in ActiveWorkbook and Break it
For x = 1 To UBound(ExternalLinks)
'remove the links with the key words "Brand Site Forecast"
If ExternalLinks(x) Like "*Brand Site Forecast*" Then
wb.BreakLink Name:=ExternalLinks(x), Type:=xlLinkTypeExcelLinks
End If
Next x
End Sub