2017-06-26 1 views
0

VBAを使用してExcelから生成するWord文書の新しい行にカーソルを移動しようとしています。VBA 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 

答えて

1

これは非常にエレガントではありませんが、後になるまで国境を延期することができます:助け

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 

希望。

+0

それはあまりエレガントではないかもしれませんが、まさにそれがやるべきことをしてくれます。ありがとう、私は本当にあなたの助けをappreaciate! – ajafarov

関連する問題