Link to home
Start Free TrialLog in
Avatar of OlympicNigel
OlympicNigelFlag for United Kingdom of Great Britain and Northern Ireland

asked on

MS Word Paragraph Formatting

Hi,

I am trying to create a Word document through VB .net and have managed to create the documents and add content through code, however I have become stuck with one aspect.

I have some content which I am trying to place into the document by pasting rtf data from the clipboard.

The data always goes into the document aligned to the very left hand side of the document.

How can I get the pasted data (RTF Text) to align say 2 tab stops in from the left?

I have tried oPara.IndentCharWidth(2) and oPara.LefIndent=(2) and numerous other combinations to no effect.

Can anyone offer any advise or code samples in VB Net?

Im using VS 2008 and Word 2010

Thanks in advance
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

This code should indent the paragraph to the second tab stop for that paragraph.

oPara.LeftIndent = oPara.TabStops(2).Position

Open in new window

Avatar of OlympicNigel

ASKER

I tried both these:

            oPara = oDoc.Content.Paragraphs.Add
            oPara.Range.Paste()
            oPara.LeftIndent = oPara.TabStops(2).Position
            oPara.Range.InsertParagraphAfter()

and

            oPara = oDoc.Content.Paragraphs.Add
            oPara.LeftIndent = oPara.TabStops(2).Position
            oPara.Range.Paste()
            oPara.Range.InsertParagraphAfter()

In both cases the pasted content remains aligned to the very left of the document.

ASKER CERTIFIED SOLUTION
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ok this gives me the pasted text at the beginning of the document. But it is indented so that is a step further.

How would I make this work so that it follows on from a previously created paragraph. The number of paragraphs will vary and not be the same.

Also, the firt methods, (and the ones previously used by me) worked with the oPara.Range.Text "Text" line but not when the Range is the pasted contents of the clipboard. Why is that?
GrahamSkan:
I managed to crack it from your second answer. Thanks
Answer required some further investigation but provided the roots to the solution
Sorry, I went out shortly after my last comment. Glad to here that you have now sorted it. Good luck with the project.
It looks obvious now, but I missed it last night; in my comment above, 'here' should have been 'hear'.