From: Harish Sharma on 8 Feb 2010 07:25 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,
From: Graham Mayor on 8 Feb 2010 07:55 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 My web site www.gmayor.com Word MVP web site http://word.mvps.org <>>< ><<> ><<> <>>< ><<> <>>< <>><<> "Harish Sharma" <HarishSharma(a)discussions.microsoft.com> wrote in message news:4098ACB3-2FA2-4BB8-94FC-E831DB7CD432(a)microsoft.com... >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,
From: Harish Sharma on 8 Feb 2010 12:41 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? "Graham Mayor" wrote: > 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 > > My web site www.gmayor.com > Word MVP web site http://word.mvps.org > <>>< ><<> ><<> <>>< ><<> <>>< <>><<> > > > > "Harish Sharma" <HarishSharma(a)discussions.microsoft.com> wrote in message > news:4098ACB3-2FA2-4BB8-94FC-E831DB7CD432(a)microsoft.com... > >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, > > > . >
From: Fumei2 via OfficeKB.com on 8 Feb 2010 14:50 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 Sharma wrote: >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] >> >> . -- Message posted via OfficeKB.com http://www.officekb.com/Uwe/Forums.aspx/word-programming/201002/1
From: Fumei2 via OfficeKB.com on 8 Feb 2010 15:11 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: >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, -- Message posted via http://www.officekb.com
|
Next
|
Last
Pages: 1 2 Prev: How do I edit a foreign language book? Next: How to record macro clicks to ribbon bar? |