Solved

Inserting an Excel worksheet into a Word doc via VB

Posted on 2002-05-13
2
346 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 100 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

Industry Leaders: 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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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
Course of the Month9 days, 13 hours left to enroll

624 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