将桌子放置在特定位置

发布于 2024-10-16 01:52:46 字数 213 浏览 1 评论 0原文

我编写了一个宏,允许用户从组合框中选择办公室分支机构,现在我想将相关地址插入到Word文档的特定位置。我使用表来保存地址,但是当创建表时,它会在光标恰好位于页面上的任何位置创建。

我似乎找不到一种方法来告诉表格将 (x,y) 精确定位在我需要它出现的位置。由于文档中除了文本之外没有其他任何内容,因此没有任何可参考的内容。

如果可能的话,我也尽量避免使用 Active X 控件。

I have written a macro to allow a user to select an office branch from a combo box, and now I want to insert the relevant address into the word document at a specific location. I have it using a table to hold the address, however when the table is created, it is created at wherever position the cursor just happens to be sitting at on the page.

I can't seem to find a way to tell the table to position exactly (x,y) where I need it to appear. Since there is nothing else in the document but text, there is nothing to reference to.

I am also trying to stay away from using Active X controls if at all possible.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

请持续率性 2024-10-23 01:52:46

此代码将在第二段和第三段之间添加一个三列一行的表格。

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

This code will add a three column, one row table between the second and third paragraphs.

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
×纯※雪 2024-10-23 01:52:46

您可以使用它来水平和垂直定位表格

tbl.Rows.HorizontalPosition = 150 'In points
tbl.Rows.VerticalPosition = 200

希望有帮助。

You may use this to position table both horizontally and vertically

tbl.Rows.HorizontalPosition = 150 'In points
tbl.Rows.VerticalPosition = 200

Hope that helped.

怀里藏娇 2024-10-23 01:52:46

我无法使用 Dick Kusleika 的答案 中的 with-statement 来理解代码,所以我想分享我的版本with-语句,对于像我这样的人来说更容易理解:

Sub InsertTable()

Dim tbl As Table
Dim pg As Paragraph

'Add a new paragraph that the table will replace
Set pg = ThisDocument.Paragraphs.Add(ThisDocument.Paragraphs(3).Range)
'Add a table in place of the new paragraph
Set tbl = ThisDocument.Tables.Add(pg.Range, 1, 3)

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

I had trouble grasping the code with the with-statement from Dick Kusleika's answer, so I'd like to share my version without the with-statement, for people like me much easier to understand:

Sub InsertTable()

Dim tbl As Table
Dim pg As Paragraph

'Add a new paragraph that the table will replace
Set pg = ThisDocument.Paragraphs.Add(ThisDocument.Paragraphs(3).Range)
'Add a table in place of the new paragraph
Set tbl = ThisDocument.Tables.Add(pg.Range, 1, 3)

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文