I'm working on spacing on a word document and I need to vary the location of page breaks and number of blank paragraphs for spacing that the macro inputs based on the number of lines of a previous paragraph so that the 2 fields that are input by the ClientNameandDate sub are on the same page.
I've used the number of agents to vary the spacing, but the problem is that some agents' information takes up more space than others, and therefore the variable length paragraph may have a different number of lines even when the number of agents is the same. This results in the macro sometimes generating a blank page, which I don't want. The HIPAANumber variable is the one that stores how many agents there are on the form. I looked at the options when I write Selection. and Selection.Paragraph. but none of the options seem to capture the information I need.
With Selection
If HIPAANumber > 2 And HIPAANumber < 5 Then
.InsertBreak Type:=wdPageBreak
End If
Call ClientNameandDate(ClientName) 'The Sub inputs the Date and Client's Name fields. These fields always take up the same amount of space.
.TypeParagraph
If HIPAANumber <= 2 Then
.InsertBreak Type:=wdPageBreak
Else
.TypeParagraph
End If
End With
Private Sub ClientNameandDate(ClientName)
Selection.TypeParagraph
With Selection
.ParagraphFormat.Alignment = wdAlignParagraphLeft
.TypeText Text:="_______________________________" 'This code inputs the Date field
.TypeText Text:=Chr(11)
.TypeText Text:="Date"
.TypeParagraph
.Font.Size = 4
.TypeText Text:=Chr(11)
.Font.Size = 12
.TypeText Text:=vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & "__________________________________________"
.TypeText Text:=Chr(11)
.TypeText Text:=vbTab & vbTab & vbTab & vbTab & vbTab & vbTab
.Font.Bold = True
.TypeText Text:=UCase(ClientName)
End With
End Sub
'''
I don't really know how to use objects in VBA, so if someone could explain how to use objects for this, I would really appreciate it. I think the easiest way to do this is to capture the number of lines of text in the paragraph that has a variable length and then use that in an If statement later, but I don't know how to capture the number of lines of text of a paragraph.