0

我需要从 excel 中调用一个 word 文件,并创建一个模板。模板将有 3 个图像 UpperLeft、Upper Right 和中央图像。

我认为这将是通过表格完成的最佳结果。

由于某种原因,我无法从 excel 创建表格..

Private Sub CommandButton13_Click()   
    'Using early binding, not late-binding
    Dim wsDoc As Word.Document
    Dim wsApp As Word.Application
    Dim wsRng As Word.Range
    Dim wsTable as Word.Table

    Dim intNoOfRows
    Dim intNoOfColumns

    Dim s As Word.InlineShape
    Dim shp As Word.Shape

    intNoOfRows = 4
    intNoOfColumns = 2

    Set wsApp = New Word.Application
    wsApp.Visible = True

    Set wsDoc = wsApp.Documents.Add
    Set wsRange = wsDoc.Content

    Set wsTable = wsDoc.Tables.Add(wsRange, intNoOfRows, intNoOfColumns)
    wsTable.Borders.Enable = True
    wsTable.Cell(1, 1).Range.InlineShapes.AddPicture _
                       UserForm1.txtImageLogoAdecco
    wsTable.Cell(1, 2).Range.ParagraphFormat.Alignment = wdAlignParagraphRight
    wsTable.Cell(1, 2).Range.InlineShapes.AddPicture _
                       UserForm1.txtImageLogoClient
    Set wsRng = wsTable.Cell(2, 1).Range
    With wsRng.Paragraphs.Add

    wsTable.Cell(2, 1).Merge MergeTo:=wsTable.Cell(2, 2)
    wsTable.Cell(2, 1).Height = 520
    wsTable.Cell(2, 1).Range.Paragraphs.Add
    wsTable.Cell(3, 1).Merge MergeTo:=objTable.Cell(3, 2)
    wsTable.Cell(3, 1).Range.Text = "Prepared by:" & "  " & UserForm1.txtPrepared
    wsTable.Cell(4, 1).Merge MergeTo:=objTable.Cell(4, 2)
    wsTable.Cell(4, 1).Range.ParagraphFormat.Alignment = wdAlignParagraphRight
    wsTable.Cell(4, 1).Range.Text = "Belgrade," & " " & Format(Date, "MMMM DD, YYYY ")

    Set wsRange = Nothing
    Set wsTable = Nothing
    Set wsDoc = Nothing
    Set wsApp = Nothing
End Sub
4

1 回答 1

0

嗯,它有点清晰,但不完全。我冒昧地编辑了您的代码,使其正确、一致且可读(没有所有空行)!

我将从清楚的部分开始: << 我想将光标向下移动几行并写一些文本。>>

要将焦点移动到表格下方,您可以获取表格的范围,然后将其折叠。例如:

Set wsRange = wsTable.Range wsRange.Collapse wdCollapseEnd '现在范围在表格后面的段落中 wsRange.Text = "表格后面的文字"

“带有背景图像,我想将其转换为形状。我想在文本后面发送”

这是我不清楚的部分。您是说要再插入一张图像并将其放在文本后面吗?使用 Shapes.Add 方法并将 WrapFormat.Type 设置为 wdWrapBehind

于 2015-10-14T16:15:35.070 回答