none
How to copy an image from clipboard to a word document? RRS feed

  • Question

  • Hello,

    Can anyone help me please. What I need is to paste an image of current form, from clipboard to a word document...

    Here is what I have so far:

    Any help is appreciated. Thanks.

    ..... 
    
    'screenshots
            PictureBox1.Image = getSnapshot(Me)
            Clipboard.SetDataObject(PictureBox1.Image)
            
    'here is where I`m getting problems....
    oDoc.RangeInlineShapes.AddPicture(Clipboard.GetDataObject.GetData(DataFormats.Bitmap))
    
            oDoc.Save()
            oDoc.Application.Quit()
    
        ' form snapshot!!!
        Private Function getSnapshot(ByVal snapshotForm As Form) As Bitmap
            With snapshotForm
                .FormBorderStyle = Windows.Forms.FormBorderStyle.None
                Dim bmp As New Bitmap(.Width + 15, .Height + 25, Imaging.PixelFormat.Format32bppArgb)
                Dim g As Graphics = Graphics.FromImage(bmp)
                g.CopyFromScreen(New Point(.Location.X, .Location.Y), New Point(0, 0), bmp.Size)
                .FormBorderStyle = Windows.Forms.FormBorderStyle.Sizable
                Return bmp
            End With
        End Function



    Alex

    Wednesday, March 13, 2013 11:26 PM

Answers

  • Hi Alex

    AddPicture can only work with a file, saved "to disk". It can't work with a memory stream or data from the clipboard.

    But you should be able to use the PASTE method to insert the data from the Clipboard.


    Cindy Meister, VSTO/Word MVP, my blog

    • Marked as answer by Alex20122012 Saturday, March 16, 2013 1:29 AM
    Friday, March 15, 2013 2:45 PM
    Moderator

All replies

  • Hi Alex

    AddPicture can only work with a file, saved "to disk". It can't work with a memory stream or data from the clipboard.

    But you should be able to use the PASTE method to insert the data from the Clipboard.


    Cindy Meister, VSTO/Word MVP, my blog

    • Marked as answer by Alex20122012 Saturday, March 16, 2013 1:29 AM
    Friday, March 15, 2013 2:45 PM
    Moderator
  • Thanks,

    That was easy

            'screenshots
            PictureBox1.Image = getSnapshot(Me)
            Clipboard.SetDataObject(PictureBox1.Image)
            oDoc.Bookmarks.Item("\endofdoc").Range.Paste()


    Alex

    Saturday, March 16, 2013 1:28 AM