View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Peter Huang [MSFT] Peter Huang [MSFT] is offline
external usenet poster
 
Posts: 225
Default Word Document that shows Excel Chart

Hi,

I had a problem with your example. I get a compile error at "Dim exapp As
Excel.Application".

Compile error:
User-defined type not defined

Do you know why?


It seems that you have not make reference to the Microsoft Excel Object
Library. You may do that by following the steps below.
1. Open the word application and Press Alt +F11, this will open Visual
Basic for Editor.
2. Select Tool/reference menu and check the Microsoft Excel 10.0 Object
Library<because mine is office 2002, so the version is 10.0
3. Copy and paste the code below to the Editor
Sub test()
Dim exapp As Excel.Application
Set exapp = New Excel.Application
exapp.Workbooks.Open "c:\book2.xls" 'you may need to establish a book2.xls
first, which include a chart in sheet1
exapp.Worksheets("Sheet1").ChartObjects(1).Chart.C hartArea.Copy
Application.ActiveDocument.Content.PasteSpecial Link:=True,
DataType:=wdPasteOLEObject
exapp.quit
set exapp = Nothing
End Sub
4. Press F5 to run the macro.

You may have a try and let me know if this does the job for you.

Also, is your command button in a Word document or and Excel workbook? I
want the end user to open up a Word document. The button should be in the
Word document and should cause the Excel chart to appear in a predetermined
place. It looks like your example creates a new Word document and displays
the chart in that document. I don't think that will work for me.


I create the sample code in VB6 not in the VBA editor of word, I am sorry
for confusion. You may refer to code above , when you run the macro above
will insert an excel chart object as a OLE object into word.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
--------------------
From: "hmmm..."
Newsgroups:

microsoft.public.excel.programming,microsoft.publi c.word.oleinterop,microsof
t.public.word.vba.general,microsoft.public.word.wo rd97vba,microsoft.public.e
xcel.charting,microsoft.public.excel.misc
References: et


Subject: Word Document that shows Excel Chart
Lines: 97
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.50.4922.1500
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4925.2800
Message-ID: . net
Date: Mon, 25 Aug 2003 16:54:12 GMT
NNTP-Posting-Host: 209.179.228.32
X-Complaints-To:
X-Trace: newsread4.news.pas.earthlink.net 1061830452 209.179.228.32 (Mon,

25 Aug 2003 09:54:12 PDT)
NNTP-Posting-Date: Mon, 25 Aug 2003 09:54:12 PDT
Organization: EarthLink Inc. --
http://www.EarthLink.net
Path:

cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed 00.sul.t-online.de!t-onlin
e.de!nntp-relay.ihug.net!ihug.co.nz!logbridge.uoregon.edu!ne wshub.sdsu.edu!e
lnk-nf2-pas!newsfeed.earthlink.net!stamper.news.pas.earthl ink.net!newsread4.
news.pas.earthlink.net.POSTED!not-for-mail
Xref: cpmsftngxa06.phx.gbl microsoft.public.word.oleinterop:8611

microsoft.public.word.vba.general:41322
microsoft.public.word.word97vba:68370 microsoft.public.excel.charting:33006
microsoft.public.excel.misc:267255 microsoft.public.excel.programming:409816
X-Tomcat-NG: microsoft.public.excel.programming

I had a problem with your example. I get a compile error at "Dim exapp As
Excel.Application".

Compile error:
User-defined type not defined

Do you know why?

Also, is your command button in a Word document or and Excel workbook? I
want the end user to open up a Word document. The button should be in the
Word document and should cause the Excel chart to appear in a predetermined
place. It looks like your example creates a new Word document and displays
the chart in that document. I don't think that will work for me.

Thanks.

"Peter Huang [MSFT]" wrote in message
...
Hi

Here is a sample code.
[Here the book2.xls located on c: have a chart on sheet1]

Private Sub Command2_Click()
Dim wd As Word.Application
Dim exapp As Excel.Application
Set wd = New Word.Application
Set exapp = New Excel.Application
exapp.Workbooks.Open "c:\book2.xls"
exapp.Worksheets("Sheet1").ChartObjects(1).Chart.C hartArea.Copy
wd.Visible = True
wd.Documents.Add.Content.PasteSpecial link:=True, DataType:=0
End Sub

Please have a try and let me if this does the job for you.
Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no

rights.

--------------------
From: "hmmm..."
Newsgroups:


microsoft.public.word.oleinterop,microsoft.public .word.vba.general,microsof

t

.public.word.word97vba,microsoft.public.excel.cha rting,microsoft.public.exc

e
l.misc,microsoft.public.excel.programming
Subject: Word Document that shows Excel Chart
Lines: 8
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.50.4807.1700
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
Message-ID: et
Date: Wed, 20 Aug 2003 17:21:52 GMT
NNTP-Posting-Host: 209.178.190.87
X-Complaints-To:
X-Trace: newsread4.news.pas.earthlink.net 1061400112 209.178.190.87

(Wed,
20 Aug 2003 10:21:52 PDT)
NNTP-Posting-Date: Wed, 20 Aug 2003 10:21:52 PDT
Organization: EarthLink Inc. --
http://www.EarthLink.net
Path:


cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfee d00.sul.t-online.de!t-onli

n

e.de!newsfeed.freenet.de!newsfeed.news2me.com!eln k-nf2-pas!newsfeed.earthli

n

k.net!stamper.news.pas.earthlink.net!newsread4.ne ws.pas.earthlink.net.POSTE

D
!not-for-mail
Xref: cpmsftngxa06.phx.gbl microsoft.public.word.vba.general:41111

microsoft.public.word.word97vba:68352

microsoft.public.excel.charting:32887
microsoft.public.excel.misc:266349
microsoft.public.excel.programming:408492
microsoft.public.word.oleinterop:8588
X-Tomcat-NG: microsoft.public.excel.programming

I would like to launch an Excel workbook from a Word document. The

workbook
updates a chart when the workbook is started. The chart must be

displayed
in the Word document.Can anyone point me in the right direction, or show

me
an example piece of code?

Thanks.