By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,052 Members | 1,201 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,052 IT Pros & Developers. It's quick & easy.

Saving Image From Clipboard

P: 3
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.InlineShape
Dim SaveObj As New DataObject
Dim ImageObj As Image
Dim WordApp As New Word.ApplicationClass
WordApp.Visible = True
Dim aDoc As Word.Document = WordApp.Documents.Open(Me.FileExtract1.Text)
Dim data As IDataObject = Clipboard.GetDataObject()
Dim fmt As String
Dim FileName As String
Dim MemStrm As MemoryStream
aDoc.Activate()
For Each InShapeObj In aDoc.InlineShapes
If InShapeObj.OLEFormat.IconLabel <> "" Then
FileName = "c:\" + InShapeObj.OLEFormat.IconLabel
InShapeObj.Select()
' WordApp.Selection.Copy()
SaveObj.SetData(DataFormats.EnhancedMetafile, WordApp.Selection)
Clipboard.SetDataObject(SaveObj)
SaveObj = Clipboard.GetDataObject()
If (SaveObj.GetDataPresent(DataFormats.EnhancedMetafi le)) Then
ImageObj = Clipboard.GetDataObject.GetData(DataFormats.Enhanc edMetafile)
--->>>>> ImageObj.Save(FileName, System.Drawing.Imaging.ImageFormat.Emf)
End If
End If
Next InShapeObj
Oct 11 '06 #1
Share this Question
Share on Google+
3 Replies


100+
P: 1,646
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.InlineShape
Dim SaveObj As New DataObject
Dim ImageObj As Image
Dim WordApp As New Word.ApplicationClass
WordApp.Visible = True
Dim aDoc As Word.Document = WordApp.Documents.Open(Me.FileExtract1.Text)
Dim data As IDataObject = Clipboard.GetDataObject()
Dim fmt As String
Dim FileName As String
Dim MemStrm As MemoryStream
aDoc.Activate()
For Each InShapeObj In aDoc.InlineShapes
If InShapeObj.OLEFormat.IconLabel <> "" Then
FileName = "c:\" + InShapeObj.OLEFormat.IconLabel
InShapeObj.Select()
' WordApp.Selection.Copy()
SaveObj.SetData(DataFormats.EnhancedMetafile, WordApp.Selection)
Clipboard.SetDataObject(SaveObj)
SaveObj = Clipboard.GetDataObject()
If (SaveObj.GetDataPresent(DataFormats.EnhancedMetafi le)) Then
ImageObj = Clipboard.GetDataObject.GetData(DataFormats.Enhanc edMetafile)
--->>>>> ImageObj.Save(FileName, System.Drawing.Imaging.ImageFormat.Emf)
End If
End If
Next InShapeObj
Perhaps this will work better:
Set ImageObj = Clipboard.GetDataObject.GetData(DataFormats.Enhanc edMetafile)
Oct 11 '06 #2

P: 3
Perhaps this will work better:
Set ImageObj = Clipboard.GetDataObject.GetData(DataFormats.Enhanc edMetafile)

Thanks, but when I put the SET in front, it goes away when I leave the line, in Studio. So, this didn't work.
Oct 12 '06 #3

100+
P: 1,646
Thanks, but when I put the SET in front, it goes away when I leave the line, in Studio. So, this didn't work.
I can see a 'SetData()' and 'GetData()' set of methods for clipboard but I can't see 'SetDataObject()' or 'GetDataObject()'

Do these methods appear on your intellisense?
Oct 12 '06 #4

Post your reply

Sign in to post your reply or Sign up for a free account.