VBA Code


Sections
Paragraphs
Sentences
Words
Characters


When modifying text it is not necessary to select the text before modifying it


activedocument.content.paragraphformat.space 2 


Dim objParagraph As Paragraph 
Set objParagraph = ActiveDocument.Paragraphs(2)
objParagraph.Alignment = wdParagraphAlignment.wdAlignParagraphLeft


Dim objRange As Range 
Set objRange = ActiveDocument.Paragraphs(2).Range
objRange.Font.Bold = True | False

Dim objFont As Font 
Set objFont = ActiveDocument.Paragraphs(2).Range.Font
objFont.Bold = True | False


objDocument.EmbedTrueTypeFonts = 

These two lines are equivalent

objDocument.Paragraphs(2).CloseUp 
objDocument.Paragraphs(2).SpaceBefore = 0

objDocument.Paragraphs(2).SpaceAfter = 0 

Dim objParagraphFormat 
objParagraphFormat = objParagraph.Format

The Range property returns a Range object that represents the portion of a document that is contained in the paragraph

objRange = objParagraph.Range 
objRange.Text = "some text"
objRange.Font.Name = "Arial"

All the properties and methods of the ParagraphFormat object are also properties and methods of the Paragraph object except the Duplicate property.




activedocument.range(start := mydoc.sentances(2).start, end := mydoc.sentances(4).end) 


Manipulates the currently selected paragraph

With Selection.Paragraphs(1).Range 
   .Font.Bold = False
End With


Get the Index number of the current paragraph

Define a range from the start of the document to the end of the first selected paragraph

Msgbox (ActiveDocument.Range(0,Selection.Paragraphs(1).Range.End).Paragraphs.Count) 

Selection.Sections(1) or Selection.Tables(1)




Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter 


Selection.ParagraphFormat.LeftIndent = InchesToPoints(2) 
Selection.ParagraphFormat.RightIndent = InchesToPoints(2)


Looping through all

Sub LoopAll 
Dim oCurrentParagraphs As Word.Range
Dim oParagraph As Word.Paragraph
Dim lParagraphNo As Long

   Application.Selection.HomeKey Unit:=WdUnits.wdStory, Extend:=WdMovementType.wdMove
   Application.Selection.Range.Select
   Do Until ((Selection.End = ActiveDocument.Content.End) Or _
             (Selection.End = ActiveDocument.Content.End - 1))
      Set oParagraph = Selection.Paragraphs(1)
      oParagraph.Range.Select

      Set oCurrentParagraphs = ActiveDocument.Range(Start:=0, End:=oParagraph.Range.End)
      lParagraphNo = oCurrentParagraphs.Paragraphs.Count

      If (Paragraph_DisplaysBullet(oParagraph.Range) = True) Then
         Debug.Print "Paragraph: " & lParagraphNo & " - has a bullet"
      End If
      
      Selection.MoveDown Unit:=WdUnits.wdParagraph, Count:=1, Extend:=WdMovementType.wdMove
   Loop
   
End Sub


© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext