Sub Main()
    Dim x As Long
    Dim y As Long
    Dim l As String
    Dim a As Variant
    
    a = Selection.Value
    If 1 < UBound(a, 1) Then
        If 1 < UBound(a, 2) Then
            LineFill a, UBound(a, 1), UBound(a, 2), 1, 1
        End If
    End If
    
    For y = LBound(a, 1) To UBound(a, 1)
        l = ""
        For x = LBound(a, 2) To UBound(a, 2)
            l = l & a(y, x)
        Next
        Debug.Print l
    Next
End Sub

Sub LineFill(a As Variant, my As Long, mx As Long, y As Long, x As Long)
    Dim i As Long
    Dim ny As Long
    Dim nx As Long
    
    For i = y + 1 To my
        If Not IsEmpty(a(i, x)) Then
            Exit For
        End If
    Next
    ny = i
    nx = x + 1
    
    For i = ny - 1 To y + 1 Step -1
        If Not IsEmpty(a(i, x + 1)) Then
            Exit For
        End If
        a(i, x) = "　"
    Next
    a(i, x) = "└"
    For i = i - 1 To y + 1 Step -1
        If IsEmpty(a(i, x + 1)) Then
            a(i, x) = "│"
        Else
            a(i, x) = "├"
        End If
    Next
    
    If nx < mx Then
        If y + 1 < ny - 1 Then
            LineFill a, ny - 1, mx, y + 1, nx
        End If
    End If
    If ny < my Then
        LineFill a, my, mx, ny, x
    End If
End Sub
