Trying load an embedded object to the clipboard and then save it to a file. When I try and save to the file, I'm getting a "Object reference not set to an instance of an object". I've marked the line with ---->>> where the error occurs. Any help would be appreciated.
Dim InShapeObj As Word.InlineShap e
Dim SaveObj As New DataObject
Dim ImageObj As Image
Dim WordApp As New Word.Applicatio nClass
WordApp.Visible = True
Dim aDoc As Word.Document = WordApp.Documen ts.Open(Me.File Extract1.Text)
Dim data As IDataObject = Clipboard.GetDa taObject()
Dim fmt As String
Dim FileName As String
Dim MemStrm As MemoryStream
aDoc.Activate()
For Each InShapeObj In aDoc.InlineShap es
If InShapeObj.OLEF ormat.IconLabel <> "" Then
FileName = "c:\" + InShapeObj.OLEF ormat.IconLabel
InShapeObj.Sele ct()
' WordApp.Selecti on.Copy()
SaveObj.SetData (DataFormats.En hancedMetafile, WordApp.Selecti on)
Clipboard.SetDa taObject(SaveOb j)
SaveObj = Clipboard.GetDa taObject()
If (SaveObj.GetDat aPresent(DataFo rmats.EnhancedM etafile)) Then
ImageObj = Clipboard.GetDa taObject.GetDat a(DataFormats.E nhancedMetafile )
--->>>>> ImageObj.Save(F ileName, System.Drawing. Imaging.ImageFo rmat.Emf)
End If
End If
Next InShapeObj
Dim InShapeObj As Word.InlineShap e
Dim SaveObj As New DataObject
Dim ImageObj As Image
Dim WordApp As New Word.Applicatio nClass
WordApp.Visible = True
Dim aDoc As Word.Document = WordApp.Documen ts.Open(Me.File Extract1.Text)
Dim data As IDataObject = Clipboard.GetDa taObject()
Dim fmt As String
Dim FileName As String
Dim MemStrm As MemoryStream
aDoc.Activate()
For Each InShapeObj In aDoc.InlineShap es
If InShapeObj.OLEF ormat.IconLabel <> "" Then
FileName = "c:\" + InShapeObj.OLEF ormat.IconLabel
InShapeObj.Sele ct()
' WordApp.Selecti on.Copy()
SaveObj.SetData (DataFormats.En hancedMetafile, WordApp.Selecti on)
Clipboard.SetDa taObject(SaveOb j)
SaveObj = Clipboard.GetDa taObject()
If (SaveObj.GetDat aPresent(DataFo rmats.EnhancedM etafile)) Then
ImageObj = Clipboard.GetDa taObject.GetDat a(DataFormats.E nhancedMetafile )
--->>>>> ImageObj.Save(F ileName, System.Drawing. Imaging.ImageFo rmat.Emf)
End If
End If
Next InShapeObj
Comment