PromisedOysterwas telling us

romisedOysternous racontait que :
Again one of those things that works when you use the macro recorder, but
then if you run the recorded macro in a perfectly similar situation, it
doesn't work anymore.
I guess you are going to have to do it the "hard way"...
Something like this in "pseudo code":
Declare a range (For the table)
Declare another range for the chart position
Declare an OLE object (For the graph)
Set the range to the target table
Set the range for the place where you want the chart to be
Set the OLE object
Use the table range to populate the OLE object data sheet
Delete the table
This would give something like:
(Remember to set a reference to the Microsoft Graph library)
'_______________________________________
Sub ConvertTableToChart()
Dim rgeInsertChart As Range
Dim rgeTable As Range
Dim oShape As InlineShape
Dim oChart As Graph.Chart
Dim i As Long
Dim j As Long
With Selection
If Not .Information(wdWithInTable) Then
MsgBox "You must position the cursor inside a table.", _
vbExclamation, "Invalid selection"
Exit Sub
End If
'If table is right at beginning of document, error will occur here _
because rgeInsertChart will equal "Nothing" _
You will need code to check for that
Set rgeInsertChart = .Tables(1).Range.Characters.First.Previous
Set rgeTable = .Tables(1).Range
rgeTable.Select
Set oShape =
Selection.InlineShapes.AddOLEObject(ClassType:="MSGraph.Chart.8", _
FileName:="", LinkToFile:=False, DisplayAsIcon:=False,
Range:=rgeInsertChart)
End With
oShape.OLEFormat.Activate
Set oChart = oShape.OLEFormat.Object
With rgeTable.Tables(1)
For i = 1 To .Columns.Count
For j = 1 To .Rows.Count
'The following allows you to manipulate the data
oChart.Application.DataSheet.Cells(j, i).Value = _
Left(.Cell(j, i).Range.Text, Len(.Cell(j, i).Range.Text) - 2)
Next
Next
End With
rgeTable.Tables(1).Delete
'The only way I kow of moving the focus off the chart... pretty lame, _
I know, but there does not seem to be any other way around that
SendKeys "{ESC}"
Selection.Collapse wdCollapseEnd
End Sub
'_______________________________________
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site:
http://www.word.mvps.org