VBA Word – 将光标移动到边界之外的新行

我正在尝试将光标移动到使用VBA从Excel生成的Word文档中的新行。

我设法添加一个新行,但是由于Word文档中的最后一个文本条目具有顶部和底部边界,因此每添加一行都保留在这些边界内。 有没有办法离开这个盒子,超越边界?

代码附上。 任何帮助,高度赞赏,谢谢!

Option Explicit Sub CreateWordDocument() Dim wdApp As Object Dim wdDoc As Object Dim wdSelection As Object Dim wdTable As Object Dim wdRange As Object Set wdApp = CreateObject("Word.Application") wdApp.Visible = True Set wdDoc = wdApp.Documents.Add Set wdSelection = wdApp.Selection With wdSelection .Font.Name = "Calibri Light" .Font.Size = "26" .Font.Color = RGB(0, 0, 0) .TypeText Text:=("TEXT 1") .ParagraphFormat.SpaceAfter = 0 .TypeParagraph .Font.Name = "Calibri Light" .Font.Size = "11" .Font.Color = RGB(128, 128, 128) .TypeText ("Text 2") .ParagraphFormat.SpaceAfter = 0 .TypeParagraph .TypeParagraph .Font.Name = "Calibri Light" .Font.Size = "11" .Font.Color = RGB(128, 128, 128) .TypeText ("Text 3") With .ParagraphFormat .Alignment = 1 .Borders(-1).LineStyle = 1 .Borders(-1).LineWidth = 2 .Borders(-3).LineStyle = 1 .Borders(-3).LineWidth = 2 End With .TypeParagraph ' !!! This line must be modified End With End Sub 

这不是很优雅,但你可以推迟到以后的边界:

 Sub CreateWordDocument() Dim wdApp As Object Dim wdDoc As Object Dim wdSelection As Object Dim wdTable As Object Dim wdRange As Object Set wdApp = CreateObject("Word.Application") wdApp.Visible = True Set wdDoc = wdApp.Documents.Add Set wdSelection = wdApp.Selection With wdSelection .Font.Name = "Calibri Light" .Font.Size = "26" .Font.Color = RGB(0, 0, 0) .TypeText Text:=("TEXT 1") .ParagraphFormat.SpaceAfter = 0 .TypeParagraph .Font.Name = "Calibri Light" .Font.Size = "11" .Font.Color = RGB(128, 128, 128) .TypeText ("Text 2") .ParagraphFormat.SpaceAfter = 0 .TypeParagraph .TypeParagraph .Font.Name = "Calibri Light" .Font.Size = "11" .Font.Color = RGB(128, 128, 128) .TypeText ("Text 3") .TypeParagraph ' !!! This line must be modified End With With wdDoc.Paragraphs(4) With .Format .Alignment = 1 .Borders(-1).LineStyle = 1 .Borders(-1).LineWidth = 2 .Borders(-3).LineStyle = 1 .Borders(-3).LineWidth = 2 End With End With End Sub 

希望有所帮助。