Anda di halaman 1dari 2

Dim fs As Object, iCellFile As Range, iCellFile2 As Range, UserRange As Range Dim StrFileName As String, HL As Hyperlink, cell As Object, count

As Integer Dim iSaveAs As Integer 'Save As and Active Cell warning iSaveAs = MsgBox(prompt:="Three conditions must be met before proceeding:" & vbN ewLine & vbNewLine & "(1) You must do a 'Save As' before this program can verify hyperlinks." & vbNewLine & "(2) The active cell must be located within the colu mn containing the hyperlinks." & vbNewLine & "(3) A backup file should be create d before proceeding." & vbNewLine & vbNewLine & "Click OK only if all 3 of these conditions have been met.", _ Buttons:=vbOKCancel, Title:="Hyperlink Validation") 'If conditions met, run macro If iSaveAs = vbOK Then prompt = "Select a range of cells to validate" Title = "Hyperlink Validation" ' Display the Input Box On Error Resume Next Set UserRange = Application.InputBox( _ prompt:=prompt, _ Title:=Title, _ Default:=ActiveCell.Address, _ Type:=8) 'Range selection Was the Input Box canceled? If UserRange Is Nothing Then MsgBox "User Aborted." Else Insert column to the right ActiveCell.Offset(0, 1).Columns("A:A").EntireColumn.Select Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove

'

'

' Extract full hyperlink path and place into newly created column for each cel l in the range For Each HL In UserRange.hyperlinks HL.Range.Offset(0, 1).Value = HL.Address Next ' Insert column to the right ActiveCell.Offset(0, 1).Columns("A:A").EntireColumn.Select Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove

' Check if each file from the hyperlink paths exist, if no path then no return , if bad path then return "No File" Set fs = CreateObject("Scripting.FileSystemObject") For Each iCellFile In UserRange.Offset(0, 1) If iCellFile = "" Then iCellFile.Offset(0, 1) = "" Else iCellFile.Offset(0, 1) = IIf(fs.FileExists(iCellFile), "OK", "No Fil e") End If Next iCellFile ' Remove hyperlink formatting for new column With Selection.Font

.ColorIndex = xlAutomatic .TintAndShade = 0 End With Selection.Font.Underline = xlUnderlineStyleNone Selection.Font.Bold = False With Selection.Interior .Pattern = xlNone .TintAndShade = 0 .PatternTintAndShade = 0 End With ' , _ TextOperator:=xlContains Selection.FormatConditions(Selection.FormatConditions.count).SetFirs tPriority With Selection.FormatConditions(1).Interior .PatternColorIndex = xlAutomatic .Color = 49407 .TintAndShade = 0 End With Selection.FormatConditions(1).StopIfTrue = False ' Count and return number of bad links as prompt count = 0 For Each cell In UserRange.Offset(0, 2) If cell.Value = "No File" Then count = count + 1 Else count = count End If Next cell MsgBox count & " bad link(s) have been highlighted" End If Else 'Conditions not met, cancel macro Exit Sub End If Conditional formatting for "No File" Selection.FormatConditions.Add Type:=xlTextString, String:="No File"

Anda mungkin juga menyukai