【发布时间】: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