469,963 Members | 1,314 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,963 developers. It's quick & easy.

Saving Image From Clipboard

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
3 6214
willakawill
1,646 1GB
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
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
willakawill
1,646 1GB
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.

Similar topics

reply views Thread by Vlado | last post: by
15 posts views Thread by Anand Ganesh | last post: by
7 posts views Thread by lgbjr | last post: by
2 posts views Thread by steve | last post: by
reply views Thread by mhospodarsky | last post: by
5 posts views Thread by exhuma.twn | last post: by
1 post views Thread by rainxy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.