473,395 Members | 1,574 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Inserting Excel file to a word document using VB.NET

Hi Friends,

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, , )

So can you please help me out?
Jul 5 '07 #1
2 4943
Please can some one help???? This is urgent for me

When I use Shapes.ADDOLEObject() function for this, I am able to insert successfully but at the starting of word. When I am doing this for 2 or 3, it was just overlapped. I want to insert 2 excel files in the word..........

Hope I am clear.........

Thanks.
Jul 9 '07 #2
Hi All,
I got the answer to my query and just want to share with you all.

m_WordDoc.InlineShapes.AddOLEObject(ClassType:="Ex cel.Sheet",FileName:=fullpath, DisplayAsIcon:=False)

AddOLEObject Method
Creates an OLE object. Returns the InlineShape object that represents the new OLE object.

expression.AddOLEObject(ClassType, FileName, LinkToFile, DisplayAsIcon, IconFileName, IconIndex, IconLabel, Range)
expression Required. An expression that returns a InlineShapes object.

ClassType Optional Variant. The name of the application used to activate the specified OLE object.

FileName Optional Variant. The file from which the object is to be created. If this argument is omitted, the current folder is used. You must specify either the ClassType or FileName argument for the object, but not both.

LinkToFile Optional Variant. True to link the OLE object to the file from which it was created. False to make the OLE object an independent copy of the file. If you specified a value for ClassType, the LinkToFile argument must be False. The default value is False.

DisplayAsIcon Optional Variant. True to display the OLE object as an icon. The default value is False.

IconFileName Optional Variant. The file that contains the icon to be displayed.

IconIndex Optional Variant. The index number of the icon within IconFileName. The order of icons in the specified file corresponds to the order in which the icons appear in the Change Icon dialog box (Insert menu, Object dialog box) when the Display as icon check box is selected. The first icon in the file has the index number 0 (zero). If an icon with the given index number doesn't exist in IconFileName, the icon with the index number 1 (the second icon in the file) is used. The default value is 0 (zero).

IconLabel Optional Variant. A label (caption) to be displayed beneath the icon.

Range Optional Variant. The range where the OLE object will be placed in the text. The OLE object replaces the range, unless the range is collapsed. If this argument is omitted, the object is placed automatically.


This has solved my problem.

Thanks.
Jul 12 '07 #3

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

Similar topics

6
by: Kerri McDonald | last post by:
We have an application where the user fills out many screens and when they are done, we are supposed to display the text they entered in a word or excel format. That is fairly easily accomplished...
4
by: Pawel | last post by:
Hello All I tried to embed Excel sheet into HTML page by following command: <iframe src="Tmp.XLS" width="100%" height="500"></iframe> and it works, showing Excel sheet inside the page, but...
4
by: Tom Dauria | last post by:
What I am trying to do is write a resume into a word document from information in an Access database. I have been using bookmarks and inserting table results into the document and so far it's...
1
by: ajk | last post by:
. Hi, All: I know how to insert files into a Word doc using C#. However, the program I've written to do this runs much too slowly. The "myObj".Application.Selection.InsertFile method executes...
17
by: Mansi | last post by:
I need to do some research on how to use excel automation from c#. Does anyone know of any good books related to this subject? Thanks. Mansi
0
by: volume | last post by:
Hi all, In an effort to try to impress the boss, I would like to log accounting information to an Excel spreadsheet using C# and .NET. This would be a mockup only, not a real solution - yet! We...
4
by: Lisa | last post by:
Hi - I'm able to open excel workbooks and word documents, but I can't seem to copy excel charts, named ranges, etc. to a word document. Anyone know of good reference material in this area? What...
7
by: Ryan | last post by:
Ok.. here's my situation. I have a program that handles a database full of people. Users of the program have the ability to send out notifications to these people. Pretty standard notifications,...
2
by: reb0101 | last post by:
hey all, I would very much appreciate any help or ideas on how to do this as I am stumped. I need to develop an access database to track documents but also link to them. I’ll explain what it...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.