Solved

Inserting an Excel worksheet into a Word doc via VB

Posted on 2002-05-13
2
340 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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

771 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now