【问题标题】:How to add multiple pictures in Word from vb.net如何从 vb.net 在 Word 中添加多张图片
【发布时间】:2021-10-30 08:20:34
【问题描述】:

我正在尝试使用 vb.net 在 word 文档中添加多张图片,但在第二张图片上,出现以下错误:System.Runtime.InteropServices.COMException: 'Error HRESULT E_FAIL has been returned from a调用 COM 组件。',我想我可能会处理一些变量,但我不知道是哪个。 这是我的代码:

Sub LoadPics()

    Dim wdWrapFront As Integer = 3
    Dim wdRelativeVerticalPositionPage As Integer = 1

    Dim objWordApp As Word.Application
    objWordApp = New Word.Application
    Dim objDoc As Word.Document
    Dim objSelection

    objDoc = objWordApp.Documents.Open("Document.doc")

    Dim objShapes As Word.InlineShapes
    objShapes = objDoc.InlineShapes
    Dim oShape As Word.Shape

    objWordApp.Visible = False

    objSelection = objWordApp.Selection
    Dim FL As string = ""

    For c As Integer = 0 to 10
                FL = "file.png"
                If IO.File.Exists(FL) Then

                    oShape = objShapes.AddPicture(FL).ConvertToShape()'<<<---here is the problem

                    With oShape
                        .WrapFormat.Type = wdWrapFront
                        .LockAspectRatio = False
                        .Height = objWordApp.CentimetersToPoints(5.08)
                        .Width = objWordApp.CentimetersToPoints(10.16)
                        .RelativeVerticalPosition = wdRelativeVerticalPositionPage
                        .Top = objWordApp.CentimetersToPoints(TopValue)
                        .Left = objWordApp.CentimetersToPoints(LeftValue)
                    End With

                Else
                    MsgBox("File doesn't exist" & vbCrLf & FL)
                End If
    Next

    objWordApp.Visible = True
    End Sub

【问题讨论】:

    标签: vb.net image ms-word dispose


    【解决方案1】:

    我可以通过简单地改变这一行来解决问题

    objWordApp.Visible = True
    

    我不知道那条线出了什么问题,但现在可以了

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-20
      • 1970-01-01
      • 2016-04-16
      • 2021-03-30
      • 1970-01-01
      相关资源
      最近更新 更多