![]() |
Confusion about paragraphs
I have created new document and inserted two paragraphs. First paragraph holds text "par2" and second paragraph holds text "par2". Now I execute the following macro (comments explain behavior).
Code:
Sub TestParagraphs() |
The problem with your code is that 'p.Range.Text = "par3"' overwrites the whole of what used to be the final paragraph, including the break. Try 'p.Range.InsertAfter "par3"' to update the new final paragraph or 'p.Range.InsertBefore "par3"' to update the old one (note that this will not delete whatever's already in that paragraph).
|
@macropod
Thanks for answer, but this Word's object model doesn't fit my mind. It's highly non-intuitive. I add paragraph with Paragraphs.Add(). Then I have these two options to obtain reference to newly created paragraph: 1) with Set p = .... and 2) Paragraphs(Paragraphs.Count). But in reality they are two different objects! Why? |
Quote:
|
Quote:
And yes - the main struggle is paragraphs and all manipulating with them. I would like you to help me with this. So, when I execute Paragraphs.Add(), I see new paragraph mark which happens to be the last one in document. So, this is my paragraph. It has a Range.Text property which can be assigned some text. What I do not understand, why p.Range.Text deletes this brand new paragraph and, moreover, replaces the text of second paragraph? Look. Paragraphs(Paragraphs.Count) refers to the same paragraph. Then why p.Range.Text fails to work when Paragraphs(3) works fine? Can you explain me more in detail? Thanks beforehand! |
Quote:
Quote:
PS If you want to reference the last paragraph, you could also use 'Set p = .Paragraphs.Last'. |
A picture is worth a thousand words.
http://i33.fastpic.ru/big/2014/0411/...3dbeb2f3a1.png |
All times are GMT -7. The time now is 07:28 AM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by
DragonByte SEO (Lite) -
vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft