Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 18th, 2006, 10:20 PM
Registered User
 
Join Date: Jan 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Inserting Excel pivot chart into Word document

I have a problem with inserting Excel Pivot Charts in Word documents and I was hoping that I someone can help.

The organisation I worked for deals with large datasets which contain health related information about our entire state (NSW). To make the information useful, staff used to create Pivot Tables/Pivot Chart for individual location, date range and disease and copy generated Pivot Charts to Word Reports. Each report contains between 320 and 680 charts. We decided to streamline the process by generating required charts using VBA and them link or copy them in Word report file. Creating pivot charts in Excel was easy; however, trying to link or copy Excel pivot charts to Word is proving to be more difficult then expected.

I just don’t seem to be able to see the chart (pivot or not) when I try to link or insert a chart into Word document.

For example, workbook called CamillaMonthlyRates1 - Total Seasonality Chart.xls has three sheets:

 
  • CTSP1 Totals (contains raw data)
  •  
  • CTSP1 Data (contains pivot table from the raw data)
     
  • CTSP1 Chart (chart built using data from CTSP1 Data)

When I manually go to Word document and click Insert, File and locate CamillaMonthlyRates1 - Total Seasonality Chart.xls I am presented with a Open Worksheet form. Open a document in Workbook combo box defaults to Entire Workbook but when I open the combo box on only has three options:

 
  • Entire Workbook
  •  
  • CTSP1 Totals
     
  • CTSP1 Data


The one I really want to I want to insert into Word document (CTSP1 Chart) isn’t listed at all in the combo box so it can not be selected. I don’t know how to do it, do you? I would love to hear from you if you do.

NOTE: I tried exporting the chart as GIF using VBA so I can link to a graphic file but that doesn’t see to work as well as we expected either.

I used the following code during testing to generate the graphic:
Code:

Code:
'Export chart as graphic 
strChartFileName = "N:\DATA\Projects\Area\CDAP\JF Charts\Charts\CTSP1" & Format(Date, "yymmdd") & ".gif" 
ActiveChart.Export Filename:=strChartFileName, FilterName:="GIF"]
This resulting file was saved as "CTSP10~1.GIF" using DOS naming convention (8 characters long) with rest of the name truncated, not as "CTSP1060119.GIF" as expected with todays (19/1/2006) save. Saved chart also looks like a screen dump; combo boxes are displayed as grey combo boxes on screen, “Drop Series Fields Here” pivot table prompt is visible in the graphic just like on the screen and the quality is not great seem more blurred then when we used Windows Copy/Paste to copy chart from Excel to Word. I tried exporting using GIF and JPG format without much difference.

Any suggestions?

 
Old January 19th, 2006, 04:00 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 180
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

Rather than using [Insert]...[File] use the [insert]...[object] instead. when prompted it will display a dialogue box which you "insert from file" rather than making a selection from the list, find the workbook and select it. It works for me. You can then automate this. Are you using word VBA or Excel VBA? you may need to utilise the automation functionality if you are going cross application.

Cheers

Matt

 
Old January 19th, 2006, 06:41 PM
Registered User
 
Join Date: Jan 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Matt,

Thanks for your input but I don't think I could use your suggestion at this stage.

I used Excel VBA to generate pivot tables and charts which are also used by other users for their own reporting needs and copied into this Word report I am trying to automate (about 500 pages report) using 320 charts. using an object would mean reprogramming Exce pivot table code. Basically each pivot chart can be used number of times to produce diffent chart by changing parameters, ie location, year, gender etc. It's easy in done in Excel and wouldn't want to start changing to Word VBA at this stage. I was playing around and figured that I could actually use Automation to achieve this objective by using the following code:

    'Copy chart graphic to Clipboard
    ActiveChart.ChartArea.Select
    ActiveChart.ChartArea.Copy

    'Paste Clipboard graphic to Word document
    objWord.Selection.PasteAndFormat (wdChartPicture)
     objWord.Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter

It worked fine in test so I hope it'll fine in production. So basically what the application does now is the following:
  • Create required pivot table and pivot chart
  • Save created workbook so it can be used by other users to check and manipulate requried data (ie change location, year, gender disease etc)

Then repeate for all required variation for the generated pivot chart (1 or more per chart)
  • Export generated chart as GIF graphic so be used by other users
  • Save generated chart to Clipboard so it can be pasted in any application
  • Use Automation and Word VBA to paste the chart at a specific bookmark in Word document
  • Repeated for all required charts
  • Save generated Word document under a new name (report plus creation date)
Done

In a nutshell, I am using Excel VBA to perform most of the work and Word VBA using automation to insert requried charts in Word report. I decided that we will have to cancel linking the charts to Word template file to make it easy to refresh once the charts are inserted. As a result each time the report needs to be refresh the whole procedure will have to run which will make it a long procedure (hours???) because we will be looking at millions of records per chart repeated 320 times.

 
Old March 15th, 2007, 03:53 PM
Registered User
 
Join Date: Mar 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I really don't understand VBA at all but I have been trying to find a way to export 100 charts out of Excel into a Word document and I came across this question. Am I on the right lines?

Can you please tell me if the following would work for me? I'm currently using MS Office 2000.

Thanks in anticipation.
Jo






Similar Threads
Thread Thread Starter Forum Replies Last Post
OWC10: binding Chart to Pivot Table rfrancisco Classic ASP Components 0 February 10th, 2006 01:47 PM
Inserting Excel pivot chart into Word documents jfejsa Word VBA 1 January 23rd, 2006 09:16 PM
Pivot Chart View Problems wall_of_jericho Access 1 July 27th, 2005 11:05 AM
open, change a excel document from word kareltje Excel VBA 2 February 14th, 2005 11:23 AM
Using Customized chart for Pivot Chart kliu9 Excel VBA 3 October 13th, 2004 09:37 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.