Solved

Inserting an Excel worksheet into a Word doc via VB

Posted on 2002-05-13
2
342 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
2 Comments
 
LVL 142

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

772 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