Здравствуйте. Я пытаюсь создать документ Word с нуля, используя Excel vba с объектами Word. Оригинальный документ длиной 2 страницы. На первой странице есть текст, затем таблица, затем текст, затем другая таблица. На второй странице есть только текст.
Я до сих пор разобрался с его частью, однако я не знаю, как переместить курсор, чтобы добавить новую таблицу. Я новичок в VBA
Sub CreateBasicWordReport()
Dim wdApp As Word.Application
Dim objRange
Dim objDoc
Dim Cell
Dim NewRange
Set wdApp = New Word.Application
With wdApp
.Visible = True
.Activate
.Documents.Add
With .Selection
.ParagraphFormat.Alignment = wdAlignParagraphCenter
.BoldRun
.Font.Size = 11
.TypeText "Letter to Proceed with Transfer"
.TypeParagraph
.Font.Size = 11
.TypeText "Determination of Transfer Value and Request for Transfer"
.TypeParagraph
.TypeParagraph
.TypeParagraph
.ParagraphFormat.Alignment = wdAlignParagraphLeft
End With
End With
Set objRange = wdApp.ActiveDocument.Range
objRange.Collapse Direction:=wdCollapseEnd
wdApp.ActiveDocument.Tables.Add objRange, 4, 2
With wdApp.ActiveDocument.Tables(1).Cell(1, 1).Range
.Bold = False
.Text = "Date"
End With
With wdApp.ActiveDocument.Tables(1).Cell(2, 1).Range
.Bold = False
.Text = "Exportin"
End With
With wdApp.ActiveDocument.Tables(1).Cell(3, 1).Range
.Bold = False
.Text = "Importing"
End With
With wdApp.ActiveDocument.Tables(1).Cell(4, 1).Range
.Bold = False
.Text = "Re"
End With
With wdApp.ActiveDocument.Tables(1).Cell(1, 2).Range
.Bold = False
.Text = "Re"
End With
With wdApp.ActiveDocument.Tables(1).Cell(2, 2).Range
.Bold = False
.Text = "Re"
End With
With wdApp.ActiveDocument.Tables(1).Cell(3, 2).Range
.Bold = False
.Text = "Re"
End With
With wdApp.ActiveDocument.Tables(1).Cell(4, 2).Range
.Bold = False
.Text = "Re"
End With
objRange.Collapse Direction:=wdCollapseEnd
wdApp.ActiveDocument.Range.InsertAfter "_____________________________________________________________________________________"
wdApp.ActiveDocument.Range.InsertAfter "Part 1"
wdApp.ActiveDocument.Bookmarks.Exists ("\EndOfDoc")
' wdApp.ActiveDocument.
'Set NewRange = ActiveDocument.Content
'NewRange.Collapse Direction:=wdCollapseEnd
'wdApp.ActiveDocument.Tables.Add (
'wdApp.ActiveDocument.Range.Collapse Direction:=wdCollapseEnd
'objRange.Collapse Direction:=wdCollapseEnd
'wdApp.ActiveDocument.Paragraphs.Add.Range.Text = "FGHFHDFg"
'wdApp.ActiveDocument.Tables.Add NewRange, 4, 2
'Set objTable = wdApp.ActiveDocument.Tabl
'objTable.Cell(1, 1).Range.Text = "WOO"
'wdApp.Documents.Add.Tables.Add wdApp.ActiveDocument.Range, 5, 4
End Sub
Первая страница
Вторая страница