Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用VBA断开Excel中包含特定单词的链接_Vba_Excel - Fatal编程技术网

使用VBA断开Excel中包含特定单词的链接

使用VBA断开Excel中包含特定单词的链接,vba,excel,Vba,Excel,我试图打破所有的链接,其中有一个关键字的链接。我不想破坏每一个环节。我见过VBA,它必须是一个完整的文件名才能工作,但我想知道是否有办法断开所有只有关键字的链接 例如,我在下面有4个链接。我只想删除与关键字“品牌网站预测”的链接,删除有它的3个链接 每日品牌网站Flash.xlsx 2018财年品牌站点预测(8月).xlsx 2018财年品牌站点预测(9月).xlsx 2018财年品牌站点预测(10月).xlsx 我试过这个,但不起作用: ActiveWorkbook.BreakLink

我试图打破所有的链接,其中有一个关键字的链接。我不想破坏每一个环节。我见过VBA,它必须是一个完整的文件名才能工作,但我想知道是否有办法断开所有只有关键字的链接

例如,我在下面有4个链接。我只想删除与关键字“品牌网站预测”的链接,删除有它的3个链接

每日品牌网站Flash.xlsx

2018财年品牌站点预测(8月).xlsx

2018财年品牌站点预测(9月).xlsx

2018财年品牌站点预测(10月).xlsx

我试过这个,但不起作用:

    ActiveWorkbook.BreakLink Name:="Brand Site Forecast", Type:=xlExcelLinks
但完整的文件名如下所示:

    ActiveWorkbook.BreakLink Name:="Brand Site Forecast FY18 (AUG).xlsx", Type:=xlExcelLinks
有什么想法吗?

试试这个

  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

谢谢你的帮助!我对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

它没有拾取链接。它会跳过您的IF条件,因为它不匹配。请检查更新的答案…您也可以使用
Instr
功能来完成此操作