Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Inserting an Excel worksheet into a Word doc via VB

Posted on 2002-05-13
2
Medium Priority
?
347 Views
Last Modified: 2012-08-14
Hi all,

Situation: I have a VB app that creates an Excel report (via the Excel.Application stuff), and now I'd like to link that Excel report into a Word doc. The AddOleObject() method works fine, but only includes the first sheet from the Excel workbook. Can anyone point me to a method that allows me to (ideally) select which worksheet to include? Or even just a method that includes ALL the worksheets from the file?

(I'm using VB6, with Word 10 and Excel 10)

TIA,

DanF
0
Comment
Question by:FaffMan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 300 total points
ID: 7005566
After defining the shape as excel.sheet, you simply display the worksheet:

dim shpExcel as Shape
...
set shpExcel = AddOleObject (...)
...
shpExcel.OLEFormat.Object.Worksheets(yousheetnumber).Activate

CHeers
0
 

Author Comment

by:FaffMan
ID: 7005580
Thanks!

Bit of tweaking required:

Dim shpExcel As Word.Shape
Dim objExcel As Object

Set shpExcel = wdDoc.Shapes.AddOLEObject(FileName:="path.to.filename", DisplayAsIcon:=False)
shpExcel.OLEFormat.Activate
Set objExcel = shpExcel.OLEFormat.Object

objExcel.Worksheets("SheetName").Activate
But you pointed me in the right direction. Thanks again.

DanF
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question