'ссылка на папку или файл
On Error Resume Next
If (InStr(dest, "../") = 1) Or (InStr(dest, "./") = 1) Then
dest = ActiveDocument.Path & "" & dest
End If
x = GetAttr(dest)
If err.Number <> 0 Then
ActiveDocument.Fields(i).Unlink: Удалено_ссылок = Удалено_ссылок + 1
End If
On Error GoTo 0
Dim bm As String
Dim src As String
Dim re_bm, ms, d, adn, cdn
Function isPathOfFileName(ByVal st As String) As Boolean
isPathOfFileName = ((InStr(st, ".") > 0) Or (InStr(st, "..") > 0) Or (InStr(st, "\") > 0) Or (InStr(st, "/") > 0))
End Function
Sub getTargets(st As String)
Set ms = re_bm.Execute(st)
bm = ""
src = ""
If (ms.Count = 1) Then
If (isPathOfFileName(ms(0))) Then
src = ms(0)
Else
bm = ms(0)
End If
End If
If (ms.Count = 2) Then
If (isPathOfFileName(ms(0))) Then
src = ms(0)
bm = ms(1)
Else
src = ms(1)
bm = ms(0)
End If
End If
If (src <> "") Then
src = Replace(src, """", "")
src = Replace(src, "file:///", "")
src = Replace(src, "%20", " ")
End If
If (bm <> "") Then
bm = Replace(bm, """", "")
End If
End Sub
Sub q177488()
Dim x As Integer
Dim fcount As Integer
Dim hl As String
Set re_bm = CreateObject("VBScript.RegExp")
With re_bm
.Global = True
.Pattern = "\x22.+?\x22"
End With
fcount = ActiveDocument.Fields.Count
For i = fcount To 1 Step -1
If (ActiveDocument.Fields(i).Type <> wdFieldHyperlink) Then
GoTo Skip
End If
hl = ActiveDocument.Fields(i).Code.Text
' ссылки на страницы в интернете и электронные письма не обрабатывать
If (InStr(hl, "mailto:") > 0) Or _
(InStr(hl, "http://") > 0) Then
GoTo Skip
End If
Call getTargets(hl)
' получение значений полей ссылок
' Ссылка на папку или файл
If (src <> "") Then
On Error Resume Next
If (InStr(src, "./") = 1) Or (InStr(src, "../") = 1) Then
' относительные пути -> в абсолютные
src = ActiveDocument.Path & "" & src
End If
x = GetAttr(src)
If err.Number <> 0 Then ' если ссылка в несуществующем направлении
Beep
ActiveDocument.Fields(i).Unlink ' преобразовать в текст
Else
If (x <> 16) Then ' если ссылка на файл
If (bm <> "") Then ' и есть ссылка на закладку в нем
adn = ActiveDocument.Name
Documents.Open src, ReadOnly = True
cdn = ActiveDocument.Name
flag = (ActiveDocument.Bookmarks.Exists(bm) = False)
Documents(cdn).Close
Documents(adn).Activate
If flag Then ' и она не найдена
Beep
ActiveDocument.Fields(i).Unlink ' преобразовать в текст
End If
End If
End If
End If
On Error GoTo 0
GoTo Skip
End If
If (bm <> "") Then ' если ссылка на закладку в текущем документе
If (ActiveDocument.Bookmarks.Exists(bm) = False) Then ' но она не найдена
Beep
ActiveDocument.Fields(i).Unlink ' преобразовать в текст
End If
GoTo Skip
End If
Skip:
Next i
End Sub
Если Вы уже зарегистрированы на Портале - войдите в систему, если Вы еще не регистрировались - пройдите простую процедуру регистрации.