PDA

View Full Version : determine the unit for left margin (Excel 2003)



uktous
03-24-2013, 12:15 AM
My home computer used Excel 2007.
When I run the code below, the margin become 2.5.

My office computer used Excel 2003.
When I run the code below, the margin become 1.

1 inch = 2.54 CM

Sub
ActiveSheet.PageSetup.LeftMargin = Application.InchesToPoints(1)
End Sub

The problem is that my office computer can read the code with correct unit (inch)
But My home computer read the code with wrong unit (cm).

How can I use Excel VBA to fix this with Excel 2003?

Thanks

Trebor76
03-24-2013, 02:09 AM
Hi uktous,

Untested, but try this:


Option Explicit

Sub Macro1()

If Application.Version >= 12 Then 'Excel 2007 is version 12.0
ActiveSheet.PageSetup.LeftMargin = Application.InchesToPoints(2.5)
Else 'Excel 2003 and prior
ActiveSheet.PageSetup.LeftMargin = Application.InchesToPoints(1)
End If

End Sub

Regards,

Robert

SamT
03-24-2013, 02:12 AM
Does this work?


Sub
Dim Inches As Double
Inches = 1
ActiveSheet.PageSetup.LeftMargin = Application.InchesToPoints(Inches)
End Sub

Sub
Dim cm As Double
cm = 2.54
Worksheets("Sheet1").PageSetup.LeftMargin = Application.CentimetersToPoints(cm)


Check your printer at home for setting/options and check excel Print Preview for settings/options

Aflatoon
03-25-2013, 03:15 AM
I don't follow the problem - the margin is set in points so the outcome should be the same regardless of whether the printer dialog shows cm or inches. Are you saying that the actual printed margin size is different between the two?