icampbell
06-27-2008, 02:36 AM
Can anyone help???
i have a small program that in turn loops through a database to return recordsets of data that i use to create ole MSGraphs that are inserted into a word document. the code that i have so far is this..
Sub AddChartBar()
Dim stData As String
Dim oShape As Word.Shape
Dim oGraphChart As Graph.Chart
'InsertLand
sql$ = "SELECT * From " & QRecs!QueryName
SQLRecs.Open sql$, cn, adOpenStatic
If SQLRecs.RecordCount <= 2 Then
AddTextNoData
SQLRecs.Close
Set SQLRecs = Nothing
Exit Sub
End If
objSelection.InsertBreak Type:=wdSectionBreakNextPage
'Embed a chart on the document.
Set oShape = objDoc.Shapes.AddOLEObject(Width:=500, Height:=400, _
ClassType:="MSGraph.Chart", DisplayAsIcon:=False, Anchor:=objSelection.Range)
Set oGraphChart = oShape.OLEFormat.Object
'Format the embedded chart.
'oGraphChart.ChartArea.Font.Size = 10
'oGraphChart.Application.Update
oGraphChart.ChartType = xl3DColumn
oGraphChart.HasTitle = True
oGraphChart.ChartTitle.Text = QRecs!Text
oGraphChart.ChartTitle.Font.Size = 10
oGraphChart.ChartArea.AutoScaleFont = True
oGraphChart.HasLegend = False
oGraphChart.ChartArea.Font.Size = 8
objSelection.ShapeRange(objSelection.ShapeRange.Count).WrapFormat.Type = wdWrapSquare
objSelection.ShapeRange(objSelection.ShapeRange.Count).WrapFormat.AllowOver lap = False
'Add data for the chart to the DataSheet in MSGraph.
i = 2
oGraphChart.Application.DataSheet.Cells.Clear
Do Until SQLRecs.EOF
'Add the chart row labels.
oGraphChart.Application.DataSheet.Cells(1, i).Value = SQLRecs.Fields(0).Value
i = i + 1
SQLRecs.MoveNext
Loop
i = 2
x = 1
Do Until x = SQLRecs.Fields.Count
'Add the chart column labels.
oGraphChart.Application.DataSheet.Cells(i, 1).Value = SQLRecs.Fields(x).Name
i = i + 1
x = x + 1
Loop
'Add data to the chart.
Dim r As Integer, c As Integer
For r = 1 To SQLRecs.Fields.Count - 1
SQLRecs.MoveFirst
For c = 2 To SQLRecs.RecordCount + 1
oGraphChart.Application.DataSheet.Cells(r + 1, c).Value = _
IIf(IsNull(SQLRecs.Fields(r).Value), 0, SQLRecs.Fields(r).Value)
SQLRecs.MoveNext
Next
Next
SQLRecs.Close
Set SQLRecs = Nothing
'objSelection.ShapeRange.ScaleHeight 0.99, msoFalse, msoScaleFromTopLeft
'objSelection.ShapeRange.ScaleWidth 0.99, msoFalse, msoscalefromright
oGraphChart.Application.Update 'Update the changes
'oGraphChart.Refresh
'oGraphChart.Application.Quit 'and deactivate the chart.
Set oGraphChart = Nothing
objSelection.EndKey (wdStory)
objSelection.TypeParagraph
End Sub
this all works fine, but what i need to do is to change the font size of both the axis and to take off the bold and also to make the text of the axis appear at a 75 degree angle.
any help on this would be great, i just cant see anything in vb to modify the axis.
thanks
Ian.
Edit Lucas: Ian, please use line breaks consistantly and use the VBA button when posting code instead of the "code" button.
i have a small program that in turn loops through a database to return recordsets of data that i use to create ole MSGraphs that are inserted into a word document. the code that i have so far is this..
Sub AddChartBar()
Dim stData As String
Dim oShape As Word.Shape
Dim oGraphChart As Graph.Chart
'InsertLand
sql$ = "SELECT * From " & QRecs!QueryName
SQLRecs.Open sql$, cn, adOpenStatic
If SQLRecs.RecordCount <= 2 Then
AddTextNoData
SQLRecs.Close
Set SQLRecs = Nothing
Exit Sub
End If
objSelection.InsertBreak Type:=wdSectionBreakNextPage
'Embed a chart on the document.
Set oShape = objDoc.Shapes.AddOLEObject(Width:=500, Height:=400, _
ClassType:="MSGraph.Chart", DisplayAsIcon:=False, Anchor:=objSelection.Range)
Set oGraphChart = oShape.OLEFormat.Object
'Format the embedded chart.
'oGraphChart.ChartArea.Font.Size = 10
'oGraphChart.Application.Update
oGraphChart.ChartType = xl3DColumn
oGraphChart.HasTitle = True
oGraphChart.ChartTitle.Text = QRecs!Text
oGraphChart.ChartTitle.Font.Size = 10
oGraphChart.ChartArea.AutoScaleFont = True
oGraphChart.HasLegend = False
oGraphChart.ChartArea.Font.Size = 8
objSelection.ShapeRange(objSelection.ShapeRange.Count).WrapFormat.Type = wdWrapSquare
objSelection.ShapeRange(objSelection.ShapeRange.Count).WrapFormat.AllowOver lap = False
'Add data for the chart to the DataSheet in MSGraph.
i = 2
oGraphChart.Application.DataSheet.Cells.Clear
Do Until SQLRecs.EOF
'Add the chart row labels.
oGraphChart.Application.DataSheet.Cells(1, i).Value = SQLRecs.Fields(0).Value
i = i + 1
SQLRecs.MoveNext
Loop
i = 2
x = 1
Do Until x = SQLRecs.Fields.Count
'Add the chart column labels.
oGraphChart.Application.DataSheet.Cells(i, 1).Value = SQLRecs.Fields(x).Name
i = i + 1
x = x + 1
Loop
'Add data to the chart.
Dim r As Integer, c As Integer
For r = 1 To SQLRecs.Fields.Count - 1
SQLRecs.MoveFirst
For c = 2 To SQLRecs.RecordCount + 1
oGraphChart.Application.DataSheet.Cells(r + 1, c).Value = _
IIf(IsNull(SQLRecs.Fields(r).Value), 0, SQLRecs.Fields(r).Value)
SQLRecs.MoveNext
Next
Next
SQLRecs.Close
Set SQLRecs = Nothing
'objSelection.ShapeRange.ScaleHeight 0.99, msoFalse, msoScaleFromTopLeft
'objSelection.ShapeRange.ScaleWidth 0.99, msoFalse, msoscalefromright
oGraphChart.Application.Update 'Update the changes
'oGraphChart.Refresh
'oGraphChart.Application.Quit 'and deactivate the chart.
Set oGraphChart = Nothing
objSelection.EndKey (wdStory)
objSelection.TypeParagraph
End Sub
this all works fine, but what i need to do is to change the font size of both the axis and to take off the bold and also to make the text of the axis appear at a 75 degree angle.
any help on this would be great, i just cant see anything in vb to modify the axis.
thanks
Ian.
Edit Lucas: Ian, please use line breaks consistantly and use the VBA button when posting code instead of the "code" button.