LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default creating and populating an excel chart from within word

Hi,

I've posted questions on a similar topic, but never managed to get to
the bottom of this issue.

Without explaining in tedious details what I am trying to do, it may be
easier to look at the following thread in word.vba.programming


http://groups.google.co.uk/group/mic...ff 2195a0dfa2

What I am trying to do is to open an instance of excel from word,
create an inline chart object, pass data to excel, then embed the
completed pie chart in word.

OK, I can manage to create an excel chart within word via VBA, but the
real difficulty seems to be either passing data to an excel range, or
simulating an excel range within word (there may be another obscure way
to do this).

The data I need to pass to the range comes from two existing arrays
that exist in the word VBA macro - I then look through them, and any
data in one loop that not '0' is passed to the range.

The whole loop is as follows [Hope it makes sense]:


Sub currentChart()


' This loop writes the data from the array to the Excel sheet


Dim oChart As Word.InlineShape
Dim wkbEmbedded As Excel.Workbook
Dim wksEmbedded As Excel.Worksheet
Dim count_classes As Integer
Dim strRange As String
count_classes = 0


Set oChart =
Selection.InlineShapes.AddOLEObject(ClassType:="Ex cel.Chart.8", _
FileName:="", LinkToFile:=False, DisplayAsIcon:=False)
Set wkbEmbedded = oChart.OLEFormat.Object
Set wksEmbedded = wkbEmbedded.Worksheets(1)


' loop through asset class array, and ignore if percentage set to 0

For intRow = 1 To UBound(serialize_current_asset_alloc_sector)


If serialize_current_asset_alloc_percentage(intRow) < "" Then
wksEmbedded.Cells(count_classes, 1).value =
serialize_current_asset_alloc_sector(intRow)
wksEmbedded.Cells(count_classes, 2).value =
serialize_current_asset_alloc_percentage(intRow)
count_classes = count_classes + 1
End If


Next intRow


' This is to select the data area to draw the graph
' A graph is always made from the selected area
strRange = "A1:" & Chr$(Asc("B") + count_classes)


With oChart.OLEFormat.Object.ActiveChart
.Range(strRange).Select
.Charts.Add
.ChartType = xl3DPieExploded


.SetSourceData Source:=wksEmbedded.Range(strRange), _
PlotBy:=xlColumns
.Location Whe=xlLocationAsObject, Name:="Current Asset
Allocation"
.HasTitle = True
.ChartTitle.Characters.Text = "Current Asset Allocation"
.ApplyDataLabels Type:=xlDataLabelsShowPercent,
LegendKey:=True, HasLeaderLines:=False
End With


End Sub


Any pointers in the right direction would be appreciated.

Rgds
Neil.

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating a Word filename shortcut in Excel Creating a Word shortcut in Excel Excel Discussion (Misc queries) 2 November 25th 07 10:33 PM
Specifying table in Word then creating it in Excel IWT Excel Programming 0 January 3rd 06 10:42 AM
Creating hangman(word game) on MS Excel nauman612 Excel Programming 8 December 11th 05 04:57 PM
Creating a Word Document from Excel Data Sheldon Excel Programming 1 September 15th 04 10:10 PM
Populating word document from userform inputs. David Goodall Excel Programming 1 December 29th 03 11:25 PM


All times are GMT +1. The time now is 08:04 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"