【问题标题】:ActiveX Image Word select from excel?ActiveX Image Word 从 excel 中选择?
【发布时间】:2015-10-08 08:19:42
【问题描述】:

我想将图像复制到 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 放在文本后面。

谢谢!

【问题讨论】:

    标签: excel word-template vba


    【解决方案1】:

    假设这是 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。您也可以将对象调暗,但没有智能感知。

    【讨论】:

    • 不幸的是,我遇到了一个错误:运行时错误'-2147418113' (8000fffff) 灾难性故障自动化错误。不必是activeX图像控件,我只需要3张图片插入word,将word路径传递给图片,并选择我想要放置它们的位置(通过书签或表格)。谢谢!
    • 好的,我已经将我的一些想法付诸实践。请查看我的帖子。我现在想要的最后一件事是将图像放在文本后面。我需要将其转换为形状对象。但我不知道如何从那里。谢谢!
    • 我认为您正在寻找 Shape.WrapFormat.Type = wdWrapBehind
    猜你喜欢
    • 2023-03-09
    • 2014-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-09
    • 2020-04-10
    • 2022-06-17
    • 1970-01-01
    相关资源
    最近更新 更多