VBA/Excel/Access/Word/Word/Word Format

Материал из VB Эксперт
Перейти к: навигация, поиск

changing the formatting of entire paragraphs is to change the style

 
Sub ChangeStyle()
    Dim wdApp As Word.Application
    Dim wdRng As Word.Range
    Dim count As Integer
    
    Set wdApp = GetObject(, "Word.Application")
    
    With wdApp.ActiveDocument
        For count = 1 To .Paragraphs.count
            Set wdRng = .Paragraphs(count).Range
            With wdRng
                If .Style = "NO" Then
                    .Style = "HA"
                End If
            End With
        Next count
    End With
    
    Set wdApp = Nothing
    Set wdRng = Nothing
End Sub



Format a Range

 
Sub ChangeFormat()
    Dim wdApp As Word.Application
    Dim wdRng As Word.Range
    Dim count As Integer
    
    Set wdApp = GetObject(, "Word.Application")
    
    With wdApp.ActiveDocument
        For count = 1 To .Paragraphs.count
            Set wdRng = .Paragraphs(count).Range
            With wdRng
                .Words(1).Font.Bold = True
            End With
        Next count
    End With
    
    Set wdApp = Nothing
    Set wdRng = Nothing
End Sub