从Excel中选择ActiveX Image Word?

时间:2015-10-08 08:19:42

标签: excel excel-vba word-template vba

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

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

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

所以,我设法将表插入到单词中,一切正常,但我只需要将backgroundImage放在文本后面。

谢谢!

1 个答案:

答案 0 :(得分: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。你也可以Dim as Object,但那时没有Intellisense。