martes, 10 de septiembre de 2013

Código que utilizo para tabular los esquemas.

Sub Tabular()
    Dim Tabs As Integer
    Tabs = 0
    QuitarIntrosDobles
    Selection.HomeKey Unit:=wdStory
    For i = 1 To 400
   
        Selection.MoveDown Unit:=wdParagraph, Count:=1
        If Selection.Text = "" Then
            Selection.Delete
        Else
            If Selection.Style = "Indices1" Then
                Tabs = 1
                Selection.Style = "Normal"
            Else
                If Selection.Style = "Indices2" Then
                    PonerTabs (1)
                    Tabs = 2
                    Selection.Style = "Normal"
                Else
                    If Selection.Style = "Indices3" Then
                        PonerTabs (2)
                        Tabs = 3
                        Selection.Style = "Normal"
                    Else 'Es normal
                        PonerTabs (Tabs)
                    End If
                End If
            End If
        End If
    Next
End Sub

Sub PonerTabs(cantidad As Integer)
    Selection.HomeKey Unit:=wdLine
    For j = 1 To cantidad
        Selection.TypeText Text:=vbTab
    Next j
End Sub

Sub QuitarIntrosDobles()
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "^p^p"
        .Replacement.Text = "^p"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    Selection.Find.Execute Replace:=wdReplaceAll
    Selection.Find.Execute Replace:=wdReplaceAll
    Selection.Find.Execute Replace:=wdReplaceAll
End Sub