PDA

View Full Version : Pushing Excel data to word



Galaxian
02-19-2012, 01:28 AM
Hi,

I have assigned an Excel macro to a content form button described as "Create letter report". I've manged to figure out how to launch a word document using that button.

However, I wish to achieve the following:

1. Push specific cell values to be incorporated within a paragraph in Word
2. Get word to display a pie chart (or similar object) shown within the Excel file

For the cell values, I've read that it might be appropriate to create a bookmark in Word and cross reference the name into the Excel VBA code, so that it can be 'replaced'. How does Word handle the formatting? Let's say the Word font is different to Excel; how do I ensure that the Word font prevails?

Can you please explain how I differentiate between different worksheets within a workbook in the macro, i.e. cell A1 sheet 1, A1 sheet 2, etc?

The idea is that Excel does the number crunching and produces nice graphs & figures. I would like the package to appear totally integrated so I want to create a button within an Excel worksheet, which can then 'export' the relevant data to a Word template.

For the objects it would appear that Word would be able to pull the pie charts, etc. through given that it will be launched using the Excel VBA code. Is this the best way and how is it done?

Very new to VBA (i only have an awareness of how to create an Excel macro by copying & pasting code), so go easy on me!

Thanks for your help.:mkay

macropod
02-27-2012, 03:19 AM
Hi Galaxian,

If you create an 'output' sheet in your workbook, on which particular cells contain the data that are needed for the Word document, you'll be able to use LINK fields in the Word document to import the data from your Excel workbook. This minimises the need for code and the need for fragile Word bookmarks. The same data links can be used multiple times, if need be. To see what's possible in this regard, copy something from your Excel workbook and, in Word, use Edit|Paste Special, click the 'paste link' option and experiment with the different paste formats.

Regarding the Pie Chart, you can create one with an embedded worksheet in the Word document, and have the values behind it based on formulae that likewise point to the data in your 'output' sheet. This further minimises the need for code.

Anne Troy
03-02-2012, 05:42 PM
Galaxian, strange you should use the word "push". I asked the guys to write this for me a long time ago. I don't know if it'll work seamlessly in a newer version, but check it out. http://www.vbaexpress.com/kb/getarticle.php?kb_id=381