Word Macro to find LeftIndent

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • skbaskar
    New Member
    • Jul 2007
    • 5

    Word Macro to find LeftIndent

    Hi All,
    I am new to vb and i tried a macro in word to find the paragraph indents and insert some tag for that indented text for e.g. indent 0.5 to 0.75 to be coded as <indent1> and 0.76 to 1.00 as “<indent2>”

    Accommodate, (66) p.22, p.24,p.55
    Acid
    <indent1>Diphos phonic Acid, (35)p.36
    <indent2>Acryli c Acid, (35) p.36-37

    And this is my code

    [CODE=vb]Sub IndentTagging()
    Indent = Val(0.5)
    With Selection.Find. ParagraphFormat
    Do While Indent <= InchesToPoints( 0.75)
    .LeftIndent = InchesToPoints( Indent)
    MsgBox ("this is left indent " & (.LeftIndent))
    With Selection.Find
    .Text = ""
    .Replacement.Te xt = "<indent1>^ &"
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .MatchWildcards = False
    End With
    Selection.Find. Execute Replace:=wdRepl aceAll
    Indent = Indent + 0.01
    MsgBox ("this is variable " & InchesToPoints( Indent))
    Loop
    End With
    End Sub[/CODE]

    The problem is when I pass the variable value to Leftindent it rounded the value i.e., 44.44 converted as 44.45 please tell me how to avoid this

    Thanks in Advance
    Baskar
    Last edited by Killer42; Jul 9 '07, 03:31 AM. Reason: Added [CODE=vb] tag
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    This may simply be a limitation inherent in the system. there are 72 points per inch, so presumably the InchesToPoints function cannot return every value between .0 and .99, but probably jumps to the nearest 100th.

    Or I could be completely wrong, of course. Try passing all the values from 0.00 to 0.99 to the function, and see what you get back.

    Comment

    • skbaskar
      New Member
      • Jul 2007
      • 5

      #3
      Originally posted by Killer42
      This may simply be a limitation inherent in the system. there are 72 points per inch, so presumably the InchesToPoints function cannot return every value between .0 and .99, but probably jumps to the nearest 100th.

      Or I could be completely wrong, of course. Try passing all the values from 0.00 to 0.99 to the function, and see what you get back.
      Hi Killer,

      First thanks for your reply and you said InchesToPoints function cannot return every value between .0 and .99 but in my code the second message box returning the values .0 to .99 even i used the InchesToPoints function and when i pass the value to .LeftIndent then only it round the number. Till i dont know how to controle it.

      Sub IndentTagging()
      Indent = Val(0.5)
      With Selection.Find. ParagraphFormat
      Do While Indent <= InchesToPoints( 0.75)
      .LeftIndent = InchesToPoints( Indent)
      MsgBox ("this is left indent " & (.LeftIndent))
      With Selection.Find
      .Text = ""
      .Replacement.Te xt = "<indent1>^ &"
      .Forward = True
      .Wrap = wdFindContinue
      .Format = True
      .MatchWildcards = False
      End With
      Selection.Find. Execute Replace:=wdRepl aceAll
      Indent = Indent + 0.01
      MsgBox ("this is variable " & InchesToPoints(Indent)) 'This message box showing the 0.0 to 0.99 values
      Loop
      End With
      End Sub

      Thanks
      Baskar K.

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        Have you checked the documentation for LeftIndent? It's conceivable that it only accepts whole point values, regardless of what the conversion function can produce. Or something.

        It looks as though LeftIndent doesn't work in my old version of Excel here at home, so I'll have to have a look in the morning when I get back to work.

        Comment

        Working...