PDA

View Full Version : Solved: determine printable page width size in points



MMehdi
11-03-2011, 06:57 AM
hi,
i am trying to make some title pages using VBA
i know the different string title width's in points using specific font name and font sizes.

and i want to know how much is the page's printable width,
so i can check if a title's size will be more than page width (it will cause it to be multiline) so i can downsize the title font so it will be fitted on one line.

thanks in advance for your help.

macropod
11-04-2011, 01:25 AM
Hi MMehdi,

Basically, you need to deduct the left & right margin sizes from the page width. The following function returns the printable width of the nominated Section in the relevant document:
Function CalcPrintWidth(StrDoc As String, lngSctn As Long)
Dim sngLeft As Single, sngRght As Single
Dim sPgWdth As Single, sngGttr As Single
With Application.Documents(StrDoc).Sections(lngSctn).PageSetup
sngLeft = .LeftMargin
sngRght = .RightMargin
sngGttr = .Gutter
sPgWdth = .PageWidth
End With
CalcPrintWidth = sPgWdth - sngLeft - sngRght - sngGttr
End Function
You could call this function with code like the follwing, passing both the document name and the number of the Section to evaluate:
Sub Test()
MsgBox CalcPrintWidth(ActiveDocument.Name, 1)
End Sub

MMehdi
11-04-2011, 02:18 PM
thanks it worked like a charm.