?
Solved

MS Word Paragraph Formatting

Posted on 2011-05-08
8
Medium Priority
?
377 Views
Last Modified: 2012-05-11
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
0
Comment
Question by:OlympicNigel
  • 4
  • 4
8 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 35715274
This code should indent the paragraph to the second tab stop for that paragraph.

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

Open in new window

0
 

Author Comment

by:OlympicNigel
ID: 35715281
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.

0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 375 total points
ID: 35715349
If the pasted text has more than one paragraph, you would only indent one paragraph.


oRange = oDoc.Range(0, 0)
oRange.Paste
oRange.Paragraphs.LeftIndent = oRange.Paragraphs(1).TabStops(2).Position

Open in new window

0
New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

 

Author Comment

by:OlympicNigel
ID: 35715434
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?
0
 

Author Comment

by:OlympicNigel
ID: 35715462
GrahamSkan:
I managed to crack it from your second answer. Thanks
0
 

Author Closing Comment

by:OlympicNigel
ID: 35715465
Answer required some further investigation but provided the roots to the solution
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 35716478
Sorry, I went out shortly after my last comment. Glad to here that you have now sorted it. Good luck with the project.
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 35717946
It looks obvious now, but I missed it last night; in my comment above, 'here' should have been 'hear'.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This tutorial provides instructions on how to properly format your Word document using the inbuilt tools provided. The benefits of using these tools means your documents are more accessible and easily portable to other applications an…
Microsoft Word is a program we have all encountered at some point, but very few of us have dug deep into its full scope of features, let alone customized it to suit our needs. Luckily making the ribbon (aka toolbar, first introduced in Word 2007) wo…
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.
This video walks the viewer through the process of creating Hyperlinks for the web and other documents. Select the "Insert" tab: Click "Hyperlink":  Type "http://" followed by a web address to reference a website or navigate to a document to ref…
Suggested Courses
Course of the Month13 days, 8 hours left to enroll

750 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question