Microsoft Word Drop Cap Feature with VBA code example

Microsoft Word Drop Cap Feature with VBA code example

DropCap

Each paragraph in a Word Document offers only one Drop Cap feature which can be enabled. Since DropCap object exposed by Paragraph object hence in this example we will iterate each paragraph in the document and enable Drop Cap for the paragraph whose text set to BOLD using VBA (Visual Basic for Application) code.

Source document

Code example

Public Sub DropCaseExample()
    'Bind active document reference
    Dim oDocument As Document
    Set oDocument = ActiveDocument
    
    'Declare paragraph object
    Dim oParagraph As Paragraph
    
    'Iterate each paragraph
    For Each oParagraph In oDocument.Paragraphs
        If oParagraph.Range.Font.Bold = True Then
            'Enable drop cap
            oParagraph.DropCap.Enable
            'Set distnace text property
            oParagraph.DropCap.DistanceFromText = 2.1
        End If
    Next oParagraph
    
    'Memory cleanup
    Set oParagraph = Nothing
    Set oDocument = Nothing
End Sub

Output

Please leave your valuable comments or queries under comment section also please do subscribe to our blogs to keep your self upto date.

Leave a Reply

Your email address will not be published.