Word文書に埋め込まれたファイルを保存するためにVBAを作成しようとしています。しかし、私はそれらを開くだけで問題が発生しています:
Sub Extract()
Dim num as Integer
Dim numObjects As Integer
numObjects = ActiveDocument.InlineShapes.count
MsgBox numObjects ' prints "11"
For num = 1 To numObjects
If ActiveDocument.InlineShapes(num).Type = 1 Then
'it's an embedded OLE type so open it.
ActiveDocument.InlineShapes(num).OLEFormat.Open
'Works for the first one but errors 5941 (the requested
' member of the collection does not exist)
End If
Next num
End Sub
このコードは、最初の埋め込みファイルがまだ開いていない場合は開きます。次のものでエラーになります。
または、最初のファイルがすでに開いている場合、マクロは何もしないように見えます。
ヒントはありますか?(私はWord 2010でこれを行っています。)
答えは非常に簡単なようです。最初の埋め込みファイルを開いた後、次の埋め込みファイルを開こうとすると、目的のドキュメントではなく、アクティブなドキュメントを参照します。次のようにオブジェクト変数を試してください。
Sub Extract()
Dim num as Integer
Dim AD as document
Set AD = activedocument
Dim numObjects As Integer
numObjects = AD.InlineShapes.count
MsgBox numObjects ' prints "11"
For num = 1 To numObjects
If AD.InlineShapes(num).Type = 1 Then
'it's an embedded OLE type so open it.
AD.InlineShapes(num).OLEFormat.Open
End If
Next num
End Sub
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加