• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 86
  • Last Modified:

Export picturebox image to word

Hello ,
How can i export picturebox images to word document.

Regards
0
RIAS
Asked:
RIAS
  • 3
  • 2
1 Solution
 
Hello ThereSystem AdministratorCommented:
There are many sample codes you can edit and use.
E.g. here.

Example:
Imports Microsoft.Office.Interop
Dim word_app As Word._Application = New  _
Word.ApplicationClass()

  ' Create the Word document.
Dim word_doc As Word._Document = _
word_app.Documents.Add()

Dim para As Word.Paragraph = word_doc.Paragraphs.Add()
para.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter
para.Range.InlineShapes.AddPicture("C:\images\image.png")
para.Range.InsertParagraphAfter()
0
 
RIASAuthor Commented:
Thanks, will try and brb
0
 
RIASAuthor Commented:
Thanks,

I have a merge document. Need to add image where te merge field is <<srce>>.
So far my code is
  Dim objWordApp As Word.Application
            objWordApp = New Word.Application
            Dim objDoc As Word.Document

            objWordApp.Documents.Open("C:\Users\PhotoTemplate.doc")
            objDoc = objWordApp.ActiveDocument

            'Open an existing document.

            objDoc.Content.Find.Execute(FindText:="<<srce>>",
ReplaceWith:="test",
Replace:=Word.WdReplace.wdReplaceAll) ''''''
            Dim oldbitmap As Bitmap = New Bitmap(Me.PicDriver.Image)
            Dim newbitmap As Bitmap = New Bitmap(CInt(100%), CInt(100%))
            Dim g As Graphics = Graphics.FromImage(newbitmap)
            g.DrawImage(oldbitmap, 0, 0, newbitmap.Width, newbitmap.Height)


            Dim pathToSavedImage As String = "C:\Users\admin.anu\Downloads\PhotoTemplate"
            newbitmap.Save(pathToSavedImage, Imaging.ImageFormat.Bmp)
            oldbitmap.Dispose()
            newbitmap.Dispose()
            g.Dispose()

            Dim ObjPic As Microsoft.Office.Interop.Word.InlineShape = objDoc.InlineShapes.AddPicture(pathToSavedImage)
            'Dim oldCopy As String
            'oldCopy = ("" & Form2.TextBox1.Text & "\" & Form1.TextBox1.Text & ".doc")
            'If System.IO.File.Exists(oldCopy) = True Then
            '    System.IO.File.Delete(oldCopy)
            'ElseIf System.IO.File.Exists(oldCopy) = False Then
            'End If
            objWordApp.Quit()
            objWordApp = Nothing

            'Code to be tested

Open in new window

0
 
RIASAuthor Commented:
Thanks
0
 
Hello ThereSystem AdministratorCommented:
I am glad I could help even if I am not VB guru. :D
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now