A
Amir
Hi!
I want to build a macro which will replace hanging indent with equivalent
number of spaces like " ".
I assume the user is using the Courier New font with the size set to 12.
I've started building it, but I don't know how to add the spaces at the
beginning of each line except for the first line in each paragraph.
Here is what i've got by now. The place where I thought about adding the
spaces is marked with ***
I would be pleased if you help me.
Kind Regards,
Amir.
=================================
Sub Macro1()
'Variables declaration and setting
Dim dcmMyDocument As Document, prgMyParagraph As Paragraph
Dim intNumberOfSpaces As Integer, intNumberOfLines As Integer
Dim blnHasHangingIndent As Boolean, blnHasFirstLineIndent As Boolean
Dim i As Integer, j As Integer
Set dcmMyDocument = ActiveDocument
For Each prgMyParagraph In dcmMyDocument.Paragraphs
'Each Paragraph variables declaration
blnHasHangingIndent = False
blnHasFirstLineIndent = False
'Defines the number of spaces that should be added to each line
intNumberOfSpaces = Abs(Round((prgMyParagraph.FirstLineIndent / 7.2),
0))
'Defines whether there is a hanging indent or first line indent
'The 7.2 number is the width in points of the Courier New font with the
size set to 12
'(Thanks to Helmut Weber and Klaus Linke who helped me to find that one
out!!!!!)
If (Round((prgMyParagraph.FirstLineIndent / 7.2), 0) < 0) Then
blnHasHangingIndent = True
End If
'Currently I want to concentrate only on the hanging indent solution so
the next 3 lines in the code has no meaning.
'If (Round((prgMyParagraph.FirstLineIndent / 7.2), 0) > 0) Then
' blnHasFirstLineIndent = True
'End If
'Cancels the hanging indent and the first line indent, then replaces the
hanging indent with spaces
If blnHasHangingIndent Then
prgMyParagraph.FirstLineIndent = 0
prgMyParagraph.LeftIndent = 0
'Defines the number of lines in the current paragraph
intNumberOfLines =
(prgMyParagraph.Next.Range.Information(wdFirstCharacterLineNumber) -
prgMyParagraph.Range.Information_
(wdFirstCharacterLineNumber))
'Supposed to loop through all the lines in the current paragraph,
starting from the second line
'(The i variable represents the current line in the specific
paragraph)
i = 2
Do While (i <= intNumberOfLines)
'***Here I want to add the spaces (intNumberOfSpaces times) at
the beginning of each line, except for the first line
For j = 1 To (intNumberOfSpaces)
'***Add Space at the beginning of the 'i' line
Next j
i = i + 1
Loop
End If
Next
End Sub
I want to build a macro which will replace hanging indent with equivalent
number of spaces like " ".
I assume the user is using the Courier New font with the size set to 12.
I've started building it, but I don't know how to add the spaces at the
beginning of each line except for the first line in each paragraph.
Here is what i've got by now. The place where I thought about adding the
spaces is marked with ***
I would be pleased if you help me.
Kind Regards,
Amir.
=================================
Sub Macro1()
'Variables declaration and setting
Dim dcmMyDocument As Document, prgMyParagraph As Paragraph
Dim intNumberOfSpaces As Integer, intNumberOfLines As Integer
Dim blnHasHangingIndent As Boolean, blnHasFirstLineIndent As Boolean
Dim i As Integer, j As Integer
Set dcmMyDocument = ActiveDocument
For Each prgMyParagraph In dcmMyDocument.Paragraphs
'Each Paragraph variables declaration
blnHasHangingIndent = False
blnHasFirstLineIndent = False
'Defines the number of spaces that should be added to each line
intNumberOfSpaces = Abs(Round((prgMyParagraph.FirstLineIndent / 7.2),
0))
'Defines whether there is a hanging indent or first line indent
'The 7.2 number is the width in points of the Courier New font with the
size set to 12
'(Thanks to Helmut Weber and Klaus Linke who helped me to find that one
out!!!!!)
If (Round((prgMyParagraph.FirstLineIndent / 7.2), 0) < 0) Then
blnHasHangingIndent = True
End If
'Currently I want to concentrate only on the hanging indent solution so
the next 3 lines in the code has no meaning.
'If (Round((prgMyParagraph.FirstLineIndent / 7.2), 0) > 0) Then
' blnHasFirstLineIndent = True
'End If
'Cancels the hanging indent and the first line indent, then replaces the
hanging indent with spaces
If blnHasHangingIndent Then
prgMyParagraph.FirstLineIndent = 0
prgMyParagraph.LeftIndent = 0
'Defines the number of lines in the current paragraph
intNumberOfLines =
(prgMyParagraph.Next.Range.Information(wdFirstCharacterLineNumber) -
prgMyParagraph.Range.Information_
(wdFirstCharacterLineNumber))
'Supposed to loop through all the lines in the current paragraph,
starting from the second line
'(The i variable represents the current line in the specific
paragraph)
i = 2
Do While (i <= intNumberOfLines)
'***Here I want to add the spaces (intNumberOfSpaces times) at
the beginning of each line, except for the first line
For j = 1 To (intNumberOfSpaces)
'***Add Space at the beginning of the 'i' line
Next j
i = i + 1
Loop
End If
Next
End Sub