Word文書を開き、名前でCommandButtonオブジェクトを探すExcelマクロを作成しています。オブジェクトが見つかると、そのオブジェクトに関連付けられているピクチャがあるかどうかを確認しようとします。オブジェクトの位置を特定しているようですが、画像のハンドルを参照しようとすると「壊滅的」な死があります。私はこれを前にやっていて、写真のハンドルがゼロであるかどうかを調べるのが私のために働いています。何がここにあるのかわからない、誰かが私が逃しているものを見ることができるかもしれない?Excel内のWord CommandButtonオブジェクトで動作しない
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Open(strFileName)
objWord.Visible = True
Set cmdSignatureButton = fncGetCommandButtonByName("NameOfCommandButtonImLookingFor", objDoc)
MsgBox "h=" & cmdSignatureButton.Picture.Handle
' It dies here, giving the error:
' Runtime error -2147418113 (8000ffff)
' Automation error
' Catastrophic failure
Private Function fncGetCommandButtonByName(strName As String, objDoc As Word.Document)
Dim obj As Object
Dim i As Integer
For i = objDoc.InlineShapes.Count To 1 Step -1
With objDoc.InlineShapes(i)
If .Type = 5 Then
If .OLEFormat.Object.Name = strName Then
Set fncGetCommandButtonByName = .OLEFormat.Object
MsgBox "Found the Command Button object" ' Seems to find the CommandButton object here
Exit Function
End If
End If
End With
Next
End Function
コードがアクセスするまでにオブジェクトを完全にロードできないのではないかと思います。これまでに作業して以来、イメージが大きくなったのか、それ以上のイメージがありますか?テストのために、 'objWord.Visible = True'の後にこの[一時停止機能](http://stackoverflow.com/questions/6960434/timing-delays-in-vba)を使用して3秒間の短い一時停止を追加するとどうなりますか? 'pause(3)' –
この場合、コマンドボタンオブジェクトに画像はありません。それはハンドルのためにゼロを返すべきです。 –
多分。ピクチャは何もありません。 – Slai