互操作性词添加赋予角色的形状-找不到类型为'ApplicationClass'的公共成员'Shapes'

时间:2019-11-07 07:26:38

标签: vb.net office-interop

我正在将图像添加到Word文件中,并且找到了一种解决方案。当我对我的代码实施该解决方案时。我正在给System.MissingMemberException:找不到类型为'ApplicationClass'的公共成员'Shares'。

    Dim autoScaledInlineShape As InlineShape = wordApp.Selection.InlineShapes.AddPicture(strImageFileName)
    Dim scaledWidth As Single = autoScaledInlineShape.Width
    Dim scaledHeight As Single = autoScaledInlineShape.Height
    autoScaledInlineShape.Delete()
    Dim newShape As Microsoft.Office.Interop.Word.Shape = wordApp.Shapes.AddShape(1, 0, 0, scaledWidth, scaledHeight)
    newShape.Fill.UserPicture(strImageFileName)
    Dim finalInlineShape As InlineShape = newShape.ConvertToInlineShape()
    finalInlineShape.Line.Visible = Microsoft.Office.Core.MsoTriState.msoFalse
    finalInlineShape.Range.Cut()
    wordApp.Selection.Paste()

谢谢。

1 个答案:

答案 0 :(得分:0)

Shapes属性属于Document类,而不是Word Application类。

Dim autoScaledInlineShape As InlineShape = wordApp.Selection.InlineShapes.AddPicture(strImageFileName)
    Dim scaledWidth As Single = autoScaledInlineShape.Width
    Dim scaledHeight As Single = autoScaledInlineShape.Height
    autoScaledInlineShape.Delete()
    Dim newShape As Microsoft.Office.Interop.Word.Shape = wordApp.ActiveDocument.Shapes.AddShape(1, 0, 0, scaledWidth, scaledHeight)
    newShape.Fill.UserPicture(strImageFileName)
    Dim finalInlineShape As InlineShape = newShape.ConvertToInlineShape()
    finalInlineShape.Line.Visible = Microsoft.Office.Core.MsoTriState.msoFalse
    finalInlineShape.Range.Cut()
    wordApp.Selection.Paste()