Pir*_*cio 2 vba ms-word word-vba
我编写了一个宏来允许用户从组合框中选择办公室分支,现在我想将相关地址插入到特定位置的word文档中.我使用表来保存地址,但是当创建表时,它会在光标恰好位于页面上的任何位置创建.
我似乎无法找到一种方法来告诉桌子准确定位(x,y)我需要它出现的位置.由于文档中没有其他内容,只有文本,因此没有任何内容可供参考.
我也试图尽可能远离使用Active X控件.
此代码将在第二段和第三段之间添加三列,一行表.
Sub InsertTable()
Dim tbl As Table
Dim pg As Paragraph
With ThisDocument
'Add a new paragraph that the table will replace
Set pg = .Paragraphs.Add(.Paragraphs(3).Range)
'Add a table in place of the new paragraph
Set tbl = .Tables.Add(pg.Range, 1, 3)
End With
tbl.Columns(1).Cells(1).Range.Text = "123 Main St"
tbl.Columns(2).Cells(1).Range.Text = "City"
tbl.Columns(3).Cells(1).Range.Text = "State"
tbl.Rows.LeftIndent = 41
End Sub
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
17849 次 |
最近记录: |