运行时错误' 462' - Excel自动化失败第二次运行代码

时间:2015-09-11 13:21:20

标签: excel vba ms-word runtime-error

我正在从excel构建word文档。当我在文档中插入图像并重新调整大小时,我得到一个运行时错误。我只是在第二次运行它时才发生。

Dim PreparedSigPath As String
Dim sWdth, sHght As Single

'file paths for image
PreparedSigPath = Range("Prepared_Sig").Value

'insert and re-size image
Set PreparedSig = docreport.Bookmarks("PREPARED_SIG").Range.InlineShapes _
    .AddPicture(PreparedSigPath)
With PreparedSig
    sWdth = .Width
    sHght = .Height
    'size to max width
    .Width = InchesToPoints(2.125)
    .Height = sHght * .Width / sWdth
    'size to max height if needed
    If .Height > InchesToPoints(0.625) Then
        .Height = InchesToPoints(0.625)
        .Width = sWdth * .Height / sHght
    End If
End With

代码在.Width = InchesToPoints(2.125)

处中断

1 个答案:

答案 0 :(得分:0)

尝试使用

.Width = Application.InchesToPoints(2.125)