var p1 = document.Paragraphs.Add(ref o);
p1.Range.InsertParagraphAfter();
現在我想抓住使用InsertParagraphAfter()創建的段落並對其進行修改。我怎樣才能訪問它?修改使用InsertParagraphAfter()添加的段落
var p1 = document.Paragraphs.Add(ref o);
p1.Range.InsertParagraphAfter();
現在我想抓住使用InsertParagraphAfter()創建的段落並對其進行修改。我怎樣才能訪問它?修改使用InsertParagraphAfter()添加的段落
InsertParagraphAfter
應該擴展當前選擇以包含新段落。因此,如果您從現有段落末尾創建空白選區開始,則應在調用InsertParagraphAfter
後將當前選區設置爲新段落。
請注意,我還沒有測試下面的代碼(我甚至沒有試過編譯它),所以我可能會離開。
var p1 = document.Paragraphs.Add(ref o);
// Set the selection to the end of the paragraph.
document.Range(p1.Range.End, p1.Range.End).Select();
p1.Range.InsertParagraphAfter();
// InsertParagraphAfter should expand the active selection to include
// the newly inserted paragraph.
var newParagraph = document.Application.Selection;
可以通過相對增加一個新段第一款實現這一點:
Paragraph p1 = document.Paragraphs.Add(System.Reflection.Missing.Value);
p1.Range.Text = "Foo";
p1.Range.InsertParagraphAfter();
// Add new paragraph relative to first paragraph
Paragraph p2 = document.Paragraphs.Add(p1.Range);
p2.Range.Text = "Bar";
p2.Range.InsertParagraphAfter();
// Add new paragraph relative to the second paragraph
Paragraph p3 = document.Paragraphs.Add(p2.Range);
p3.Range.Text = "Baz";
根據MSDN的說法,當您按段落進行響應時,將會在範圍之前創建段落。 您的樣品的結果應該是這樣的: BazBarFoo 如果你想要的東西看起來像: 富 酒吧 巴茲 你應該使用下列內容: '段落P1 = document.Paragraphs.Add (System.Reflection.Missing.Value); p1.Range.Text =「Foo」; 段落p2 = p1.Range.Paragraphs.Add(System.Reflection.Missing.Value); p2.Range.Text =「Bar」; 段落p3 = p2.Range.Paragraphs.Add(System.Reflection.Missing.Value); p3.Range.Text =「Baz」;' – 2015-10-21 14:05:29
這遺憾的是不工作:(也許你能幫助我,雖然我爲什麼這樣做的原因。是將兩個表分開,這樣它們就不會被字自動合併,但是我希望這些表能夠直接疊加在另一個表上。通過執行一個InsertParagraphAfter(),整行換行將兩個表分開,我想修改新的段落,以便表格正確對齊。有什麼不同的方式來完成我所尋找的內容嗎? – sooprise 2012-03-07 16:30:38
@sooprise:試試doi在錄製一個宏的時候,你想在Word中做什麼,然後在VBA中查看代碼。也許這可以給你一個關於如何完成的提示? – 2012-03-07 19:09:51
試過這個,不幸的是沒有得到我想要的結果。 – sooprise 2012-03-08 21:19:45