Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Creating a Word filename shortcut in Excel | Excel Discussion (Misc queries) | |||
Specifying table in Word then creating it in Excel | Excel Programming | |||
Creating hangman(word game) on MS Excel | Excel Programming | |||
Creating a Word Document from Excel Data | Excel Programming | |||
Populating word document from userform inputs. | Excel Programming |