Article ID: 176443
Article Last Modified on 11/23/2006
Sub CreateGraphFromFile()
Dim oGraph As Object
Dim oDataSheet As Object
Dim shpGraph As PowerPoint.Shape
Dim lRowCnt As Long
Dim lColCnt As Long
Dim lValue As Long
' Add the graph to the slide.
With ActivePresentation.Slides(1)
' Create the Graph object on the slide.
Set shpGraph = .Shapes.AddOLEObject(ClassName:="MSGraph.Chart", _
Link:=msoFalse)
End With
' Set references.
Set oGraph = shpGraph.OLEFormat.Object
Set oDataSheet = oGraph.Application.DataSheet
' Place headers into data table.
' Create four column headers.
oDataSheet.Cells(1, 2).Value = "Col1"
oDataSheet.Cells(1, 3).Value = "Col2"
oDataSheet.Cells(1, 4).Value = "Col3"
oDataSheet.Cells(1, 5).Value = "Col4"
' Create four row headers.
oDataSheet.Cells(2, 1).Value = "Row1"
oDataSheet.Cells(3, 1).Value = "Row2"
oDataSheet.Cells(4, 1).Value = "Row3"
oDataSheet.Cells(5, 1).Value = "Row4"
' We already know the number of columns and rows
' from the data we are importing.
Open "<YourPathAndFileNameHere>" For Input As #1
' Get four rows of data.
For lRowCnt = 2 To 5
For lColCnt = 2 To 5
' Get value from file.
Input #1, lValue
' Place in data table.
oDataSheet.Cells(lRowCnt, lColCnt).Value = lValue
Next lColCnt
Next lRowCnt
Close #1
' Release the reference.
Set oGraph = Nothing
Set oDataSheet = Nothing
End Sub
120802 Office: How to Add/Remove a Single Office Program or Component
163435 VBA: Programming Resources for Visual Basic for Applications
Additional query words: ppt97 8.0 graph97 ppt98 graph98
Keywords: kbdtacode kbinfo kbprogramming KB176443