Загрузка данных


Sub ShiftTimePlus4()
    Dim rng As Range
    Dim txt As String
    Dim re As Object, matches As Object, m As Object
    Dim h As Integer, mi As Integer
    Dim newTime As String
    
    Set re = CreateObject("VBScript.RegExp")
    re.Global = True
    re.Pattern = "\b([01]?\d|2[0-3]):([0-5]\d)\b"
    
    Set rng = ActiveDocument.Content
    txt = rng.Text
    
    Set matches = re.Execute(txt)
    
    ' Обрабатываем с конца, чтобы не сбить позиции
    Dim i As Long
    For i = matches.Count - 1 To 0 Step -1
        Set m = matches(i)
        h = CInt(m.SubMatches(0))
        mi = CInt(m.SubMatches(1))
        
        h = (h + 4) Mod 24
        newTime = Format(h, "00") & ":" & Format(mi, "00")
        
        rng.Start = m.FirstIndex
        rng.End = m.FirstIndex + m.Length
        rng.Text = newTime
    Next i
    
    MsgBox "Готово! Время сдвинуто на +4 часа."
End Sub