0

我想将图像复制到 Word 中的 ActiveX 图像控件。

我认为可以通过 .InlineShapes(index) 来完成,但我只有控件的名称..

Private Sub CommandButton13_Click()


 Dim intNoOfRows

 Dim intNoOfColumns

 Dim objWord

 Dim objDoc

 Dim objRange

 Dim objTable

Dim s As Word.InlineShape
Dim shp As Shape
intNoOfRows = 4

intNoOfColumns = 2

Set objWord = CreateObject("Word.Application")

objWord.Visible = True

Set objDoc = objWord.Documents.Add

Set objRange = objDoc.Range

objDoc.Tables.Add objRange, intNoOfRows, intNoOfColumns

Set objTable = objDoc.Tables(1)

objTable.Borders.Enable = True



  objTable.Cell(1, 1).Range.InlineShapes.AddPicture UserForm1.txtImageLogo
  objTable.Cell(1, 2).Range.ParagraphFormat.Alignment = wdAlignParagraphRight
  objTable.Cell(1, 2).Range.InlineShapes.AddPicture   UserForm1.txtImageLogoClient






objTable.Cell(2, 1).Merge MergeTo:=objTable.Cell(2, 2)

objTable.Cell(2, 1).Height = 520

With objWord
Set s = objTable.Cell(2,  1).Range.InlineShapes.AddPicture(UserForm1.txtImageBackground)
s.Height = 510
s.Width = 460


End With

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


  Set objTable = Nothing


  End Sub

所以,我已经成功地将表格插入到 word 中,一切正常,但我只需要将 backgroundImage 放在文本后面。

谢谢!

4

1 回答 1

0

假设这是 Developer/Controls/Legacy Tools/ActiveX 中的 Image 控件:

Dim ax As MsForms.Image
Set ax = ActiveDocument.InlineShapes(1).OLEFormat.Object
ax.Picture = LoadPicture("C:\Users\Public\Pictures\Sample Pictures\Koala.jpg")

您需要访问 InlineShape 的 OLEFormat.Object 才能处理其公共 COM 属性和方法。旧的 ActiveX 控件实际上是 UserForm 控件,因此如果您使用严格类型声明它,您将获得 Intellisense。您也可以将对象调暗,但没有智能感知。

于 2015-10-08T16:43:10.843 回答