Points to Centimeteres

J

JB

Hi Folks,
I've written a macro that displays certain properties of styles such as
font size and paragraph spacing but I'm not sure how to translate pt
into cm.

Any pointers?

J
 
J

Jay Freedman

JB said:
Hi Folks,
I've written a macro that displays certain properties of styles such
as font size and paragraph spacing but I'm not sure how to translate
pt into cm.

Any pointers?

J

I guarantee you're going to groan when you read this:

Use the PointsToCentimeters function.

For example, PointsToCentimeters(Selection.Font.Size) will display the font
size at the cursor in centimeters.
 
J

JB

Jay said:
I guarantee you're going to groan when you read this:

Use the PointsToCentimeters function.

For example, PointsToCentimeters(Selection.Font.Size) will display the font
size at the cursor in centimeters.
Hi Guys,
this does not seem to work for me....

The GUI reports 1.5cm which is reported in code as 56.75pt.

When I use " PointsToCentimeters(Sty.ParagraphFormat.LeftIndent) " it
reports 2.002014

Any Ideas?

J
 
K

Klaus Linke

The GUI reports 1.5cm which is reported in code as 56.75pt.
When I use " PointsToCentimeters(Sty.ParagraphFormat.LeftIndent) "
it reports 2.002014


Hi J,

56.7 pt *is* about 2 cm.

Are you sure you're looking at the same value in code and the GUI (...
paragraph indent vs. style indent, for example)?

Greetings,
Klaus
 
J

JB

Klaus said:
Hi J,

56.7 pt *is* about 2 cm.

Are you sure you're looking at the same value in code and the GUI (...
paragraph indent vs. style indent, for example)?

Greetings,
Klaus
Yeah I think so...the GUI path is Format > Style> (select style type
which is paragraph style) then Modify > Format > Paragraph and it's the
left indentation i'm interested in.

Code = PointsToCentimeters(Sty.ParagraphFormat.LeftIndent)

Does this look OK?

J
 
K

Klaus Linke

Yeah I think so...the GUI path is Format > Style> (select style type
which is paragraph style) then Modify > Format > Paragraph and it's the
left indentation i'm interested in.

Code = PointsToCentimeters(Sty.ParagraphFormat.LeftIndent)

Does this look OK?


Looks OK... though it doesn't work that way any more in my Word2002.
You might use Ctrl+Q (=ResetPara) first, so Word doesn't think you want to
modify the style by example (if you happen to be in a paragraph with manual
formatting).

If the GUI shows 1.5 cm, and your code shows 2 cm (= 56.75 pt), one of them
must be wrong ;-)

Regards,
Klaus
 
J

JB

Klaus said:
Looks OK... though it doesn't work that way any more in my Word2002.
You might use Ctrl+Q (=ResetPara) first, so Word doesn't think you want to
modify the style by example (if you happen to be in a paragraph with manual
formatting).

If the GUI shows 1.5 cm, and your code shows 2 cm (= 56.75 pt), one of them
must be wrong ;-)

Regards,
Klaus
So How does it work in 2002 Klaus?

J
 
H

Helmut Weber

Hi,
looks funny, but should convince you,
that the calculation is correct.
MsgBox CentimetersToPoints(PointsToCentimeters(56))
MsgBox PointsToCentimeters(CentimetersToPoints(1.975556))
 
J

JB

Helmut said:
Hi,
looks funny, but should convince you,
that the calculation is correct.
MsgBox CentimetersToPoints(PointsToCentimeters(56))
MsgBox PointsToCentimeters(CentimetersToPoints(1.975556))
---
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000
lol I do believe you but I'm still stuck on this :)

Just out of interest what differs in what I'm trying to do in 2000 and 2003?

Cheers

J
 
H

Helmut Weber

Hi J,
I don't have all relevant versions of word available,
but I don't think, there are relevant differences concerning
your issue. Maybe the following will shed some light on this.
It is nothing but the coding of paragraph indent vs. style indent,
as Klaus suggested.
---
Dim StyleName As String ' the style name
Dim LeftActPt As Single ' actual left indent in points
Dim LeftDefPt As Single ' default left indent inpoints
Dim LeftActCm As Single ' actual left indent in centimeters
Dim LeftDefCm As Single ' default left indent centimeters
StyleName = Selection.Paragraphs(1).Style
LeftActPt = Selection.Paragraphs(1).LeftIndent
LeftDefPt =
ActiveDocument.Styles(StyleName).ParagraphFormat.LeftIndent
LeftActCm = PointsToCentimeters(LeftActPt)
LeftDefCm = PointsToCentimeters(LeftDefPt)
MsgBox "actual left indent = " & Format(LeftActCm, "#.000 cm")
MsgBox "default left indent = " & Format(LeftDefCm, "#.000 cm")
 
J

JB

Helmut said:
Hi J,
I don't have all relevant versions of word available,
but I don't think, there are relevant differences concerning
your issue. Maybe the following will shed some light on this.
It is nothing but the coding of paragraph indent vs. style indent,
as Klaus suggested.
---
Dim StyleName As String ' the style name
Dim LeftActPt As Single ' actual left indent in points
Dim LeftDefPt As Single ' default left indent inpoints
Dim LeftActCm As Single ' actual left indent in centimeters
Dim LeftDefCm As Single ' default left indent centimeters
StyleName = Selection.Paragraphs(1).Style
LeftActPt = Selection.Paragraphs(1).LeftIndent
LeftDefPt =
ActiveDocument.Styles(StyleName).ParagraphFormat.LeftIndent
LeftActCm = PointsToCentimeters(LeftActPt)
LeftDefCm = PointsToCentimeters(LeftDefPt)
MsgBox "actual left indent = " & Format(LeftActCm, "#.000 cm")
MsgBox "default left indent = " & Format(LeftDefCm, "#.000 cm")
---
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
Hi Helmut,
The code below is what I have...(all relevant arrays are declared as
Single).
I think this returns the next styles value for LeftIndent but everything
else looks OK.

Any Ideas?

Cheers

J

Dim Sty As Style
i = 0
For Each Sty In ActiveDocument.Styles
If Not Sty.BuiltIn Then
ReDim Preserve aStyArrName(i)
ReDim Preserve aStyArrSize(i)
ReDim Preserve aStyArrFont(i)
ReDim Preserve aStyArrStyleType(i)
ReDim Preserve aStyArrParAlign(i)
ReDim Preserve aStyArrParaOutLine(i)
ReDim Preserve aStyArrParaLeftInd(i)
ReDim Preserve astyarrparaRightInd(i)
ReDim Preserve astyarrparaSpBef(i)
ReDim Preserve astyarrparaSpAft(i)
ReDim Preserve astyarrparaLineSp(i)
aStyArrName(i) = Sty.NameLocal
aStyArrSize(i) = Sty.Font.Size
aStyArrFont(i) = Sty.Font.Name
If Sty.Type <> wdStyleTypeCharacter Then
aStyArrStyleType(i) = "Paragraph"
aStyArrParAlign(i) = Sty.ParagraphFormat.Alignment
aStyArrParaOutLine(i) = Sty.ParagraphFormat.OutlineLevel
aStyArrParaLeftInd(i) =
PointsToCentimeters(Sty.ParagraphFormat.LeftIndent)
astyarrparaRightInd(i) = Sty.ParagraphFormat.RightIndent
astyarrparaSpBef(i) = Sty.ParagraphFormat.SpaceBefore
astyarrparaSpAft(i) = Sty.ParagraphFormat.SpaceAfterAuto
astyarrparaLineSp(i) = Sty.ParagraphFormat.LineSpacing
Else
aStyArrStyleType(i) = "Character"
End If
i = i + 1
End If
Next
 
K

Klaus Linke

Hi JB,

If Sty.Type <> wdStyleTypeCharacter Then
aStyArrStyleType(i) = "Paragraph"

That's not true any more. There now are list styles and table styles, too
(and they have messed up many, many of my old macros).

Best make a "Select Case Sty.Type" with Cases for wdStyleTypeParagraph,
Character, List and Table (and perhaps a "Case Else" for the case that MS
thinks up something new in the next version).

Regards,
Klaus
 
H

Helmut Weber

Hi JB,
this goes beyond my abilities.
I think this returns the next styles value for LeftIndent
How about the first style, do you get it's value at all?
How about the last style, when there is no next one?
If I don't reply anymore, I don't know any more.
You wouldn't be the first one, to detect a real bug...
 
J

JB

Thanks for the help guys! It seems I'm getting the appropriate readings
for everything to do with the style I call except this particular
indentation.

I'm thinking that while the GUI reports 1.5CM and the Code reports 2cm,
as this is an old-ish template that changes over time are being held
somewhere and this is leading to teh reporting problem.

I've created a brand new document with some new styles holding the same
settings to test my code and it works exactly as I want it to so this
maybe supports my theory above.

Last Question is :- Does the document hold old formatting somewhere
(like bloat) and if so is there any way to view the document outside
word or maybe in rtf that will show all this junk?

Thanks Again

J
 
J

JB

Klaus said:
Hi JB,

If Sty.Type <> wdStyleTypeCharacter Then
aStyArrStyleType(i) = "Paragraph"

That's not true any more. There now are list styles and table styles, too
(and they have messed up many, many of my old macros).

Best make a "Select Case Sty.Type" with Cases for wdStyleTypeParagraph,
Character, List and Table (and perhaps a "Case Else" for the case that MS
thinks up something new in the next version).

Regards,
Klaus
Hi Klaus,
I'm REALLY beginning to dislike Micro$oft

Cheers

J
 

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