【问题标题】:Bulk Url checker macro excel批量 URL 检查器宏 excel
【发布时间】:2016-02-26 06:13:51
【问题描述】:

我正在寻求帮助,因为我有大量链接来检查链接是否损坏我已经尝试了下面的宏,但它工作了两次,之后它不再工作我正在使用 ms office 10 64bit 我想如果宏添加宏 可以检查图像分辨率,例如,如果我在 A 列上粘贴 url,它将突出显示损坏的链接,在 b 列上它将显示图像分辨率

Sub Audit_WorkSheet_For_Broken_Links()

If MsgBox("Is the Active Sheet a Sheet with Hyperlinks You Would Like to Check?", vbOKCancel) = vbCancel Then

    Exit Sub

End If

On Error Resume Next
For Each alink In Cells.Hyperlinks
    strURL = alink.Address

    If Left(strURL, 4) <> "http" Then
        strURL = ThisWorkbook.BuiltinDocumentProperties("Hyperlink Base") & strURL
    End If

    Application.StatusBar = "Testing Link: " & strURL
    Set objhttp = CreateObject("MSXML2.XMLHTTP")
    objhttp.Open "HEAD", strURL, False
    objhttp.Send

    If objhttp.statustext <> "OK" Then

        alink.Parent.Interior.Color = 255
    End If

Next alink
Application.StatusBar = False
On Error GoTo 0
MsgBox ("Checking Complete!" & vbCrLf & vbCrLf & "Cells With Broken or Suspect Links are Highlighted in RED.")

End Sub

【问题讨论】:

  • 很确定您不会从 HEAD 请求中获得分辨率(您的意思是尺寸吗?)。
  • 当你说它工作两次时,你的意思是它只工作两次吗?或者,如果您退出并重新打开 Excel,是否可以再次运行宏?
  • 如果我无法获得解决方案,我很好,我的下一个任务是删除死链接请帮助我希望这个宏突出显示死链接
  • 是的,它只工作了两次,再也不能工作了
  • 注释掉On Error Resume Next这一行,看看是否有任何错误产生

标签: vba excel macros


【解决方案1】:

编辑:我更改了您的宏以正确声明变量并在宏完成时释放对象;这应该解决任何潜在的内存问题。请尝试此代码并告诉我它是否有效。

Sub Audit_WorkSheet_For_Broken_Links()

If MsgBox("Is the Active Sheet a Sheet with Hyperlinks You Would Like to Check?", vbOKCancel) = vbCancel Then

    Exit Sub

End If

Dim alink As Hyperlink
Dim strURL As String
Dim objhttp As Object

On Error Resume Next
For Each alink In Cells.Hyperlinks
    strURL = alink.Address

    If Left(strURL, 4) <> "http" Then
        strURL = ThisWorkbook.BuiltinDocumentProperties("Hyperlink Base") & strURL
    End If

    Application.StatusBar = "Testing Link: " & strURL
    Set objhttp = CreateObject("MSXML2.XMLHTTP")
    objhttp.Open "HEAD", strURL, False
    objhttp.Send

    If objhttp.statustext <> "OK" Then

        alink.Parent.Interior.Color = 255
    End If

Next alink
Application.StatusBar = False

'Release objects to prevent memory issues
Set alink = Nothing
Set objhttp = Nothing
On Error GoTo 0
MsgBox ("Checking Complete!" & vbCrLf & vbCrLf & "Cells With Broken or Suspect Links are Highlighted in RED.")

End Sub

下面的旧答案

将您的宏(似乎来自here)与在excelforum 上找到的替代方法相结合会产生以下代码。试一试,让我知道它是否适合你。

Sub TestHLinkValidity()
Dim rRng As Range
Dim fsoFSO As Object
Dim strPath As String
Dim cCell As Range

If MsgBox("Is the Active Sheet a Sheet with Hyperlinks You Would Like to Check?", vbOKCancel) = vbCancel Then

    Exit Sub

End If

Set fsoFSO = CreateObject("Scripting.FileSystemObject")
Set rRng = ActiveSheet.UsedRange.Cells
For Each cCell In rRng.Cells
    If cCell.Hyperlinks.Count > 0 Then
        strPath = GetHlinkAddr(cCell)
        If fsoFSO.FileExists(strPath) = False Then cCell.Interior.Color = 65535
   End If
Next cCell
End Sub

Function GetHlinkAddr(rngHlinkCell As Range)
    GetHlinkAddr = rngHlinkCell.Hyperlinks(1).Address
End Function

【讨论】:

  • 对不起它对我不起作用----Set fsoFSO = CreateObject("Scripting.FileSystemObject")
  • @cath 你遇到错误了吗?您正在运行什么操作系统和 Excel 版本?我刚刚在 Windows 10、Excel 2013 上对此进行了测试,没有出现任何错误。
  • 我使用的是 windows 8.1 和 excel 2013
  • 实际上我没有收到任何错误,但它只是不工作它没有突出死链接
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-05-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-07-19
  • 2011-09-28
  • 1970-01-01
相关资源
最近更新 更多