Thanks for all the assistance!
Here is what I ended the prototyping phase with. This seemed to work
consistantly too. It can modified to pass arguments for the source of
the data (sheet name), column ranges to Include/Exclude, and such.
The embedded object doesn't have to be in the form of "Object1", it
could be a name that makes more sense like "My Widget Sales".
Sub xUpdateEmbeddedGraph()
Dim objGraph As Object ' Use Late binding
Dim dsGraph As Object '
Dim lngRow As Long
Dim intCol As Integer
Dim nRowStart As Integer
Dim nRowEnd As Integer
Dim nColStart As Integer
Dim nColEnd As Integer
Application.ScreenUpdating = False
' Build arTemp for this data.
' DATA GATHERING -----------------------------------------------------
' I used a temporary array to hold the values I would be applying
later
Worksheets("Sheet1").Select
ReDim arTemp(10, 68) ' 10 rows by 68 columns.
nRowStart = 1
nRowEnd = 10
nColStart = 1
nColEnd = 68
Dim n, nn, k
k = 0
For n = nRowStart To nRowEnd
For nn = nColStart To nColEnd
arTemp(n, nn) = Cells(n, nn)
Next nn
Next n
' Sheet that contains the target embedded chart
--------------------------
Worksheets("Where My Chart Is").Activate
ActiveSheet.Shapes("Object1").Select ' object could be a name too,
like "My Widgets"
' Adding this line made the behavior consistant for effecting changes
in the datasheet
Selection.Verb Verb:=xlPrimary
Set objGraph = ActiveSheet.Shapes("Object1").OLEFormat.Object
Set dsGraph = objGraph.Object.Application.DataSheet
For lngRow = 1 To UBound(arTemp, 1)
For intCol = 1 To UBound(arTemp, 2)
dsGraph.Cells(lngRow, intCol) = arTemp(lngRow, intCol)
Next
Next
' When fresh data is written to the data sheet in this fashion, the
Include/Exlude formatting is lost.
' This is where I must reset the Included/Excluded columns for display
in Excel
n = 0
With dsGraph
For n = 2 To 15 ' These, of course, can be calculated values.
.Columns(n).Include = False
Next n
End With
n = 0
With dsGraph
For n = 30 To 68 ' These can be calculated values too.
.Columns(n).Include = False
Next n
End With
' The seemed to update without this, however, it's here just in case.
objGraph.Object.Application.Update
objGraph.Object.Application.Quit
Set objGraph = Nothing
Set dsGraph = Nothing
End Sub