none
Word 2007 Border RRS feed

  • Question

  • Hello,

    When a border is drawn around the text in MS Word. The box takes some space around the line which re arranges the whole line to accommodate the extra space needed by the box. I want to have the border around the text but it should not occupy any additional space for it.

    If you see line 1, the length is longer than the line 2, which has no border around the text. Is there a way to do this?

    This is a test

    This is a test

    Thanks, Mohan

    Thursday, April 14, 2011 2:36 PM

All replies

  • Hi Mohan

    You're trying to do this as an end-user? The best place to ask this kind of question is the Answers site. MSDN targets developers (programmers), so the replies you get here will tend to be code, not step-by-step instructions :-)

    http://answers.microsoft.com/en-us/office/forum/word

    Don't forget to mention the version of Word you're working with, as that will affect the instructions.

    FWIW, I think if you go to the Paragraphs dialog box and set the Line Height to an exact value that might help?


    Cindy Meister, VSTO/Word MVP
    Thursday, April 14, 2011 3:43 PM
    Moderator
  • Thanks Cindy.

    I am trying to do it programatically and not as an end user.

     

    Thanks, Mohan

    Thursday, April 14, 2011 4:00 PM
  • Hi Mohan,

    There will always be a little extra length because of the left and right border.  However, your example appears to be selecting not only the text but also the space following. So I would suggest double-checking your text selection method.

    Here is code that I clipped from VBA that inserts a box around a word:

        With Selection.Font

            With .Borders(1)

                .LineStyle = wdLineStyleSingle

                .LineWidth = wdLineWidth050pt

                .Color = wdColorAutomatic

            End With

            .Borders.Shadow = False

        End With

    It produced a text line as follows:

    Now is the time

     

    Hope this helps

     


    Regards
    Thursday, April 14, 2011 4:40 PM
  • Thanks for the reply.

    But I need to have a border around the text without any spaces taken. Can shapes can be used to solve this?

     

    Regards, Mohan

     

    Thursday, April 14, 2011 4:50 PM
  • Hi Mohan,

    Maybe we need to define what is meant by length ... visual or digital?

    The digital length of the line example I provided is the same whether the the text borders are there or not. However, the visual length may in fact appear different but that is due to the width of the border being applied.

    The border width I applied was half a point, which is hardly noticable. However, if the requirement is to make the bordered text occupy the same physical space then you might experient with the fonts spacing for the bordered text elements. The command is "range.font.spacing = 0.25"

    Hope this helps


    Regards
    Thursday, April 14, 2011 6:00 PM
  • It's all about visual length and I do it programatically moving from word to word and it seems to be disturbing visually. That's what I would like to avoid. Now I am trying with shape where I am moving the shape over the word and there is no disturbance now, but I can't edit anything inside the rectangle shape. (Shapes.AddShape(msoShapeRectangle, 10, 10, 60, 10)

    Also this action goes into Undo/Redo stack which I don't want to.

    Any pointers is greatly appreciated.

    Regards, Mohan



    Thursday, April 14, 2011 9:45 PM
  • Hi Mohan,

    Can you move the shape over the word and then give the shape a  Fill.Visible = msoFalse command? I think this will allow the underlying text to show through the shape.


    Regards
    Friday, April 15, 2011 3:46 AM
  • It's all about visual length and I do it programatically moving from word to word and it seems to be disturbing visually. That's what I would like to avoid. Now I am trying with shape where I am moving the shape over the word and there is no disturbance now, but I can't edit anything inside the rectangle shape. (Shapes.AddShape(msoShapeRectangle, 10, 10, 60, 10)

    Also this action goes into Undo/Redo stack which I don't want to.




    You can't affect the Undo stack in Word 2007, but this would be possible in Word 2010 to a limited extent.

    Position the rectange BEHIND the text instead of in front and the text should lay "over" the rectangle and thus be accessible.


    Cindy Meister, VSTO/Word MVP
    Friday, April 15, 2011 6:32 AM
    Moderator
  • Thanks Cindy. I am doing that now. But the text below couldn't be editable. I would like to edit the text below the text as well.

    Is there a way to do it? Is there any code samples for it?

     

    And there any other approaches you can shed some light on?

     

    Thanks, Mohan

    Friday, April 15, 2011 2:31 PM
  • Thanks Cindy. I am doing that now. But the text below couldn't be editable. I would like to edit the text below the text as well.

    Is there a way to do it? Is there any code samples for it?

     And there any other approaches you can shed some light on?


    Hi Mohan

    I'm not following what you mean by the "text below". Whether you mean vertically on the page, or 3-dimensionally, as in the document "layer" (layer = graphics-on-top, text, graphics-under-text).

    Programmatically you should be able to edit any text in an unprotected document....

    Other approaches. Well... The idea of a TextBox (AutoShape) did go through my mind. But that would cause other kinds of problems so I didn't mention it before.


    Cindy Meister, VSTO/Word MVP
    Friday, April 15, 2011 2:48 PM
    Moderator
  • Thanks Rich,

    Fill.Visible = msoFalse Helped.

    Now I can able to edit the text below the Rectangle shape.


    Regards, Mohan

     

    Friday, April 15, 2011 3:25 PM
  • The example below has a text "This" inside a Rectangle shape and this text in a Word Document.

    This   is a test.

     

    Problem:

    I would like to move a "BOX" over the text in a document programatically.

    1. Box should not occupy space. (With Shapes object, I kind of solved it. But this action goes into the Undo/Redo stack. I would like to avoid it.)

     

    Is there any other solution to this problem other than Shapes? Something like using System.Drawing or Windows COM dll's ...

    Regards, Mohan

    Friday, April 15, 2011 3:40 PM
  • Hello,

    have you tried the following to clear the undo buffer?

     activedocument.UndoClear

    Regards,
    Lars-Eric

    Friday, April 15, 2011 5:44 PM
  • No Lars-Eric. That won't work for me.

    Thanks, Mohan


    Problem is to solve this portion. Undo/redo can be handled.

    I would like to move a "BOX" over the text in a document programatically.

    1. Box should not occupy space.

    Is there any windows API's to do it. I can get x,y,height,width from Range object using Information. If there are any API's out there

    other than Microsoft Word Interop, that would be helpful.

    Any pointers are appreciated.

     

    Thanks, Mohan

    Wednesday, April 20, 2011 4:06 PM
  • Hello Mohan,

    I would not recommend you to try to go to deep, like Win API :-)

    Through Windows API's you can do almost anything you want to do, but not with every thing. If you can get a handle to the DeviceContext Word is using to 'draw' the document, you could do almost anything on that area, but it would be rather useless. As soon as the DC (DeviceContext) has to be repainted (scolling, area uncovered when a windows is moved and so on) Word knows what to draw on that area, but has no idea what you might have done via Win API's. If you would use Win API to draw you own stuff on the DC there would be very very tricky for you to intercept the Windows messages for that Window and repaint your own stuff. Not to mention when if you want the document printed, which is also done to a DeviceContext, but a printer DC

    My conclusion is if you can't do it via Word's API, don't do it.

    Regards,
    Lars-Eric

    Wednesday, April 20, 2011 5:25 PM