Inserting Excel file data to a word document using VB.NET

santuvssantu

New member
Joined
Jul 5, 2007
Messages
2
Programming Experience
1-3
Hi All,

I have tried inserting an excel file to a word document.But the following code is inserting the junk information. So can you please help me out?

Dim m_WordApp As New Word.Application
Dim m_WordDoc As Word.Document


m_WordDoc = m_WordApp.Documents.Open(CObj("C:\Documents and Settings\santu\My Documents\New Microsoft Word Document.doc"), CObj(False), CObj(False), CObj(False))

Dim fullpath As String = "C:\Documents and Settings\santu\My Documents\Certification Details.xls"
m_WordDoc.Application.Selection.EndKey(WdUnits.wdS tory)
m_WordDoc.Application.Selection.InsertBreak(WdBrea kType.wdPageBreak)

m_WordDoc.Application.Selection.InsertFile(fullpat h)
m_WordDoc.Application.Selection.InsertParagraphAft er()

Even i have tried using this also...
m_WordDoc.Range.InsertParagraphAfter()
m_WordDoc.Range.InsertFile(fullpath, , 0, , )

I want to insert all the content of the excel.....when i am using the same for copying word doc to word it is working fine but with excel i m getting this problem. Hope I explained clearly.
So can you please help me out?
 
i hope this helps you..


Dim WithEvents xlbook As Excel.Workbook
xlbook = GetObject("c:\master.xls")

selectedsheet = textbox1.text
Dim ws As Excel.Worksheet = CType(xlbook.Worksheets(selectedsheet), Excel.Worksheet)

for irow=1 to ws.usedrange.rows.count

for icol=1 to ws.usedrange.count

msgbox(ws.Cells(irow, icol).Value())
next
next

now write it in doc file
 
Hi Shrey,
Thanks for your reply.
I got it in the other way.

Dim fullpath As String = "C:\Temp\Certification Details.xls"

m_WordDoc.Application.Selection.EndKey(WdUnits.wdStory)
m_WordDoc.Application.Selection.InsertBreak(WdBreakType.wdPageBreak)
m_WordDoc.InlineShapes.AddOLEObject(FileName:=fullpath, DisplayAsIcon:=False)

Thanks,
Santuvssantu.
 
Back
Top