Page Margin issue

H

Harish Sharma

I am not sure what is wrong with the below code:

'I am expecting to get value for left margin and right margin and then use
those values to get the page area. However I am not getting correct left and
right margin value.

the message box shows " R Margin: 9999999 Left Margin: 9999999 Page width:
612"

I am not sure why it is showing such huge value for R margin and left margins.

Private Sub PageArea()

Dim PArea, RMargin, LMargin As Double

RMargin = ActiveDocument.PageSetup.RightMargin
LMargin = ActiveDocument.PageSetup.LeftMargin
PArea = ActiveDocument.PageSetup.PageWidth-(LMargin +RMargin)

MsgBox "R margin: " & RMargin & " Left Margin: " & LMargin & " Page Width: "
& PArea

End Sub

Thanks,
 
G

Graham Mayor

Use the following instead. Choose inches or centimeters.

Private Sub PageArea()

Dim PArea, RMargin, LMargin

'RMargin = PointsToInches(ActiveDocument.PageSetup.RightMargin)
RMargin = PointsToCentimeters(ActiveDocument.PageSetup.RightMargin)
'LMargin = PointsToInches(ActiveDocument.PageSetup.LeftMargin)
LMargin = PointsToCentimeters(ActiveDocument.PageSetup.LeftMargin)
'PArea = PointsToInches(ActiveDocument.PageSetup.PageWidth - (LMargin +
RMargin))
PArea = PointsToCentimeters(ActiveDocument.PageSetup.PageWidth - (LMargin +
RMargin))
MsgBox "R margin: " & RMargin & " Left Margin: " & LMargin & " Page Width: "
& PArea
End Sub

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
H

Harish Sharma

Graham,

thanks for your prompt response. I tried your code using pointsToCentimeters.
However, this is the message I am getting

" R Margin: 352777.8Left Margin: 352777.8 Page width: -705533.9099"

It is very high for a page width or page margin. Is there any problem with
initialization or some problem with the system setting that I need to take
care of?
 
F

Fumei2 via OfficeKB.com

I am not sure what th eproblem is, but going back to the PointToInches
(rather than PointToCentimeters)...

Sub PageArea_1()
Dim PArea, RMargin, LMargin
RMargin = PointsToInches(ActiveDocument.PageSetup.RightMargin)
LMargin = PointsToInches(ActiveDocument.PageSetup.LeftMargin)
PArea = PointsToInches(ActiveDocument.PageSetup _
.PageWidth - (LMargin + RMargin))

PArea = PointsToInches(ActiveDocument.PageSetup _
.PageWidth - (LMargin + RMargin))
MsgBox "R margin: " & RMargin & vbCrLf & _
"Left Margin: " & LMargin & vbCrLf & _
"Page Width: " & PArea
End Sub

gives me:

Left Margin: 1.25
Right Margin: 1.25
Page Width: 8.465278

which...is wrong. It should be not:

PArea = PointsToInches(ActiveDocument.PageSetup _
.PageWidth - (LMargin + RMargin))

BUT

PArea = PointsToInches(ActiveDocument.PageSetup _
.PageWidth) - (RMargin + LMargin)

which gives:

Left Margin: 1.25
Right Margin: 1.25
Page Width: 6

which is correct:

8.5 - (1.25 + 1.25)
8.5 - 2.5

= 6

PointsToCentimeters also gives the correct result (with the proper use of
brackets):

Sub PageArea_1()
Dim PArea, RMargin, LMargin

RMargin = PointsToCentimeters(ActiveDocument.PageSetup.RightMargin)
LMargin = PointsToCentimeters(ActiveDocument.PageSetup.LeftMargin)

PArea = PointsToCentimeters(ActiveDocument.PageSetup _
.PageWidth) - (RMargin + LMargin)

MsgBox "R margin: " & RMargin & vbCrLf & _
"Left Margin: " & LMargin & vbCrLf & _
"Page Width: " & PArea
End Sub

Left Margin: 3.175
Right margin: 3.175
Page Area: 15.24

with the incorect brackets:

PArea = PointsToCentimeters(ActiveDocument.PageSetup _
.PageWidth - (LMargin + RMargin))


you get:

Left Margin: 3.175
Right margin: 3.175
Page Area: 21.36599

It is decidely incorrect as PageWidth alone:

PArea = PointsToCentimeters(ActiveDocument.PageSetup _
.PageWidth)

is 21.59.

21.59 - (3.175 + 3.175)
21.59 - 6.35
15.24



Harish said:
Graham,

thanks for your prompt response. I tried your code using pointsToCentimeters.
However, this is the message I am getting

" R Margin: 352777.8Left Margin: 352777.8 Page width: -705533.9099"

It is very high for a page width or page margin. Is there any problem with
initialization or some problem with the system setting that I need to take
care of?
Use the following instead. Choose inches or centimeters.
[quoted text clipped - 44 lines]
 
F

Fumei2 via OfficeKB.com

Bottom line:

"I am not sure why it is showing such huge value for R margin and left
margins."

It is because Margins are in POINTS.

On my computer:

ActiveDocument.PageSetup.RightMargin = 90

PointsToCentimeters(ActiveDocument.PageSetup.RightMargin) = 3.175
PointsToInches(ActiveDocument.PageSetup.RightMargin) = 1.25
 
H

Harish Sharma

Fumei2,

I found that this macro is running correctly in another document. Only in
one particular document it is giving this error. I am not sure why it is so.
I checked the page size and margin but they are normal

Left margin =0.5 inch
Right margin =0.5 inch
width=8.5 inch
Height=11 inch

thanks
 
D

Daniel Rikowski

The 9999999 is not an actual margin. It is a placeholder value because the document you are using has more than one section.

Because each section can have its own page setup, many properties of ActiveDocument.PageSetup have no meaning and the properties return 9999999.

The correct way would be to use ActiveDocument.Sections(?).PageSetup instead.






Harish Sharma wrote:

Fumei2,I found that this macro is running correctly in another document.
09-Feb-10

Fumei2

I found that this macro is running correctly in another document. Only i
one particular document it is giving this error. I am not sure why it is so
I checked the page size and margin but they are norma

Left margin =0.5 inc
Right margin =0.5 inc
width=8.5 inc
Height=11 inc

thank

:

Previous Posts In This Thread:

Page Margin issue
I am not sure what is wrong with the below code

'I am expecting to get value for left margin and right margin and then us
those values to get the page area. However I am not getting correct left an
right margin value

the message box shows " R Margin: 9999999 Left Margin: 9999999 Page width
612

I am not sure why it is showing such huge value for R margin and left margins

Private Sub PageArea(

Dim PArea, RMargin, LMargin As Doubl

RMargin = ActiveDocument.PageSetup.RightMargi
LMargin = ActiveDocument.PageSetup.LeftMargi
PArea = ActiveDocument.PageSetup.PageWidth-(LMargin +RMargin

MsgBox "R margin: " & RMargin & " Left Margin: " & LMargin & " Page Width:
& PAre

End Su

Thanks,

Use the following instead. Choose inches or centimeters.
Use the following instead. Choose inches or centimeters

Private Sub PageArea(

Dim PArea, RMargin, LMargi

'RMargin = PointsToInches(ActiveDocument.PageSetup.RightMargin
RMargin = PointsToCentimeters(ActiveDocument.PageSetup.RightMargin
'LMargin = PointsToInches(ActiveDocument.PageSetup.LeftMargin
LMargin = PointsToCentimeters(ActiveDocument.PageSetup.LeftMargin
'PArea = PointsToInches(ActiveDocument.PageSetup.PageWidth - (LMargin
RMargin)
PArea = PointsToCentimeters(ActiveDocument.PageSetup.PageWidth - (LMargin
RMargin)
MsgBox "R margin: " & RMargin & " Left Margin: " & LMargin & " Page Width:
& PAre
End Su

-
<>>< ><<> ><<> <>>< ><<> <>>< <>><<
Graham Mayor - Word MV

My web site www.gmayor.co
Word MVP web site http://word.mvps.or
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

Graham,thanks for your prompt response.
Graham

thanks for your prompt response. I tried your code using pointsToCentimeters
However, this is the message I am gettin

" R Margin: 352777.8Left Margin: 352777.8 Page width: -705533.9099

It is very high for a page width or page margin. Is there any problem wit
initialization or some problem with the system setting that I need to tak
care of

:

I am not sure what th eproblem is, but going back to the PointToInches(rather
I am not sure what th eproblem is, but going back to the PointToInche
(rather than PointToCentimeters)..

Sub PageArea_1(
Dim PArea, RMargin, LMargi
RMargin = PointsToInches(ActiveDocument.PageSetup.RightMargin
LMargin = PointsToInches(ActiveDocument.PageSetup.LeftMargin
PArea = PointsToInches(ActiveDocument.PageSetup
..PageWidth - (LMargin + RMargin)

PArea = PointsToInches(ActiveDocument.PageSetup
..PageWidth - (LMargin + RMargin)
MsgBox "R margin: " & RMargin & vbCrLf &
"Left Margin: " & LMargin & vbCrLf &
"Page Width: " & PAre
End Su

gives me

Left Margin: 1.2
Right Margin: 1.2
Page Width: 8.46527

which...is wrong. It should be not

PArea = PointsToInches(ActiveDocument.PageSetup
..PageWidth - (LMargin + RMargin)

BU

PArea = PointsToInches(ActiveDocument.PageSetup
..PageWidth) - (RMargin + LMargin

which gives

Left Margin: 1.2
Right Margin: 1.2
Page Width: 6

which is correct:

8.5 - (1.25 + 1.25)
8.5 - 2.5

= 6

PointsToCentimeters also gives the correct result (with the proper use of
brackets):

Sub PageArea_1()
Dim PArea, RMargin, LMargin

RMargin = PointsToCentimeters(ActiveDocument.PageSetup.RightMargin)
LMargin = PointsToCentimeters(ActiveDocument.PageSetup.LeftMargin)

PArea = PointsToCentimeters(ActiveDocument.PageSetup _
..PageWidth) - (RMargin + LMargin)

MsgBox "R margin: " & RMargin & vbCrLf & _
"Left Margin: " & LMargin & vbCrLf & _
"Page Width: " & PArea
End Sub

Left Margin: 3.175
Right margin: 3.175
Page Area: 15.24

with the incorect brackets:

PArea = PointsToCentimeters(ActiveDocument.PageSetup _
..PageWidth - (LMargin + RMargin))


you get:

Left Margin: 3.175
Right margin: 3.175
Page Area: 21.36599

It is decidely incorrect as PageWidth alone:

PArea = PointsToCentimeters(ActiveDocument.PageSetup _
..PageWidth)

is 21.59.

21.59 - (3.175 + 3.175)
21.59 - 6.35
15.24



Harish Sharma wrote:

Bottom line:"I am not sure why it is showing such huge value for R margin and
Bottom line:

"I am not sure why it is showing such huge value for R margin and left
margins."

It is because Margins are in POINTS.

On my computer:

ActiveDocument.PageSetup.RightMargin = 90

PointsToCentimeters(ActiveDocument.PageSetup.RightMargin) = 3.175
PointsToInches(ActiveDocument.PageSetup.RightMargin) = 1.25



Harish Sharma wrote:

--


Fumei2,I found that this macro is running correctly in another document.
Fumei2,

I found that this macro is running correctly in another document. Only in
one particular document it is giving this error. I am not sure why it is so.
I checked the page size and margin but they are normal

Left margin =0.5 inch
Right margin =0.5 inch
width=8.5 inch
Height=11 inch

thanks

:


Submitted via EggHeadCafe - Software Developer Portal of Choice
How to Annotate Images from a database in a web page
http://www.eggheadcafe.com/tutorial...9-082c24acd999/how-to-annotate-images-fr.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top