PDA

View Full Version : Solved: Determine distance of text from margin



newbie101
05-19-2013, 05:19 AM
Hi Folks,

Wondering if anyone will be able to help me here (I'm a newbie so please take it easy on me).

I'm trying to put together a function that will return whether text on a given page reaches the bottom and or top margins (depending on the layout of the page).

I really have no clue how to begin, so I'd appreciate some pointers, and I'll post back any progress and or questions.

Thank you all, and have a great day!

macropod
05-19-2013, 11:24 PM
You could use code like:
Sub GetVerticalPosition()
Application.ScreenUpdating = False
Dim sTopMargin As Single, sBottomMargin As Single, sBottomLine As Single
Dim sPageHeight As Single, sPrintHeight As Single, sVertPos As Single
With Selection.Characters.First
sVertPos = .Information(wdVerticalPositionRelativeToTextBoundary) + _
.ParagraphFormat.SpaceBefore
With .PageSetup
sTopMargin = .TopMargin
sBottomMargin = .BottomMargin
sPageHeight = .PageHeight
End With
sPrintHeight = sPageHeight - sTopMargin - sBottomMargin
MsgBox "The top of the first selected character is " & sVertPos & _
" points below the top margin and " & sPrintHeight - sVertPos & _
" points above the bottom margin."
End With
Application.ScreenUpdating = True
End Sub

newbie101
05-20-2013, 11:21 PM
Thank you, you really helped me.:bow: