如何使用VBA Word文档中的表格后,把光标

问题描述 投票:1回答:1

我已经没有一个模板来创建Word文档中的报告。这份报告由来自MS访问记录 - 并且会有一些文本,然后一个表的基础上,记录(我将创建动态使用VBA基于记录的#表)#迭代。我可以开始使用书签作为起点,然后能够添加表并填写细胞在Word文档中插入文本。这个问题做一次表中填写我怎样才能把光标放在下一行表之后开始插入文本。以下是我的一些提示或示例代码会有人欣赏 - 谢谢!

    Set wordObj = CreateObject("Word.Application")

    Set wordDoc = wordObj.Documents.Open(fileName:=wrdTMPLT, Visible:=True)

    wordDoc.Bookmarks("rptdate").Range.Text = Format(DATE, "dd-mmm-yyyy")
    Set wordrange = wordDoc.GoTo(what:=wdGoToBookmark, Name:="startpoint")      'set cursor to start point

    wordrange.Text = Me.Text3_CHK

    Set wordrange = wordDoc.GoTo(what:=wdGoToBookmark, Name:="tblpoint")      'set cursor to location to insert table

    Set tbl = wordDoc.Tables.Add(Range:=wordrange, numrows:=4, numcolumns:=2)

    tbl.CELL(1, 1).Merge MergeTo:=tbl.CELL(1, 2)
    tbl.CELL(3, 1).Merge MergeTo:=tbl.CELL(3, 2)
    tbl.CELL(4, 1).Merge MergeTo:=tbl.CELL(4, 2)

    tbl.CELL(1, 1).Range.InsertAfter "Title: "
    tbl.CELL(2, 1).Range.InsertAfter "Coordinator: "
    tbl.CELL(2, 2).Range.InsertAfter "Engineer: "
    tbl.CELL(3, 1).Range.InsertAfter "Vendor 1: "
    tbl.CELL(3, 2).Range.InsertAfter "Vendor 2: "
    tbl.CELL(4, 1).Range.InsertAfter "Contractor: "

    tbl.Borders.Enable = False

    'Following text to enter after the table above                       
    wordrange.Text = "HellO"

    'continue with next table ... n text/table cycle  based  # of records
ms-word access-vba cursor-position
1个回答
0
投票

要到下表中的点(段),分配表的范围为Range对象,然后就崩了终点:

Dim rng as Word.Range
'Do things here until table is finished
Set rng = tbl.Range
rng.Collapse wdCollapseEnd
'Now the Range is after the table, so do things with it, for example:
rng.Text = "more text"
© www.soinside.com 2019 - 2024. All rights reserved.