ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Charting in VBA problem (https://www.excelbanter.com/excel-programming/348576-charting-vba-problem.html)

jmacclure

Charting in VBA problem
 

I'm trying to create a form code that will make a chart and display i
in the form and am having some trouble with the code for creating th
chart. I am using OfficeXP.

Here is the code section that I am having problems with and the issu
written behind.



Dim myChtObj As ChartObject
Dim myNewSeries1 As Series
Dim myXValues As Range
Dim myYValues1 As Range
Dim myName1 As Range
Dim myName2 As String
Dim myChtTitle As String
Dim myAxisTitle As String

Private Sub cmdShowChart_Click()

Call GetValues 'Gets values, ranges, etc for populating th
chart

Set myChtObj = ActiveSheet.ChartObjects.Add _
(Left:=1000, Width:=528, Top:=100, Height:=282)
Set myNewSeries1 = myChtObj.Chart.SeriesCollection.NewSeries
With myNewSeries1
.Name = myName1
.Values = myYValues1
.XValues = myXValues
.Border.ColorIndex = 11
.Border.Weight = xlThin
.Border.LineStyle = xlContinuous
.MarkerBackgroundColorIndex = 11 ~Get a "Unabl
to set the MarkerBackgroundColorIndex property of the Series class
error
'.MarkerBackgroundColor = 11 ~Trie
this to see if it made a difference - no luck
.MarkerForegroundColorIndex = 11 ~Sam
type of error
.MarkerStyle = xlMarkerStyleDiamond ~Sam
type of error
.MarkerSize = 5
.Smooth = False
~Same type of error
.Shadow = False
.ApplyDataLabels xlDataLabelsShowValue
End With
With myChtObj.Chart
.ChartType = xlLineMarkers
.HasTitle = True
.ChartTitle.Characters.Text = myChtTitle
.HasLegend = False
With .Axes(xlValue, xlPrimary)
.HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text
myAxisTitle ~Object doesn't support this property or method
End With
With .Axes(xlCategory, xlPrimary)
.HasTitle = False
With .TickLabels
.Alignment = xlCenter
.Offset = 100
.ReadingOrder = xlContext
.Orientation = 45
End With
End With
With .PlotArea
.Left = 1
.Top = 24
.Width = 354
.Height = 186
End With
End With
End If

' Save chart as GIF
Fname = ThisWorkbook.Path & Application.PathSeparator & "temp.gif"
~Type Mismatch
myChtObj.Chart.Export Filename:=Fname, FilterName:="GIF"

' Load Image to Form
Image1.Picture = LoadPicture(Fname)



I would appreciate any hel

--
jmacclur
-----------------------------------------------------------------------
jmacclure's Profile: http://www.excelforum.com/member.php...fo&userid=2979
View this thread: http://www.excelforum.com/showthread.php?threadid=49502


David Welch[_3_]

Charting in VBA problem
 
Hi,

You should set the chart type to xlLine before setting the markers. The
default chart type is (I think) a column chart, which doesn't have markers.

jmacclure wrote:
I'm trying to create a form code that will make a chart and display it
in the form and am having some trouble with the code for creating the
chart. I am using OfficeXP.

Here is the code section that I am having problems with and the issue
written behind.



Dim myChtObj As ChartObject
Dim myNewSeries1 As Series
Dim myXValues As Range
Dim myYValues1 As Range
Dim myName1 As Range
Dim myName2 As String
Dim myChtTitle As String
Dim myAxisTitle As String

Private Sub cmdShowChart_Click()

Call GetValues 'Gets values, ranges, etc for populating the
chart

Set myChtObj = ActiveSheet.ChartObjects.Add _
(Left:=1000, Width:=528, Top:=100, Height:=282)
Set myNewSeries1 = myChtObj.Chart.SeriesCollection.NewSeries
With myNewSeries1
.Name = myName1
.Values = myYValues1
.XValues = myXValues
.Border.ColorIndex = 11
.Border.Weight = xlThin
.Border.LineStyle = xlContinuous
.MarkerBackgroundColorIndex = 11 ~Get a "Unable
to set the MarkerBackgroundColorIndex property of the Series class"
error
'.MarkerBackgroundColor = 11 ~Tried
this to see if it made a difference - no luck
.MarkerForegroundColorIndex = 11 ~Same
type of error
.MarkerStyle = xlMarkerStyleDiamond ~Same
type of error
.MarkerSize = 5
.Smooth = False
~Same type of error
.Shadow = False
.ApplyDataLabels xlDataLabelsShowValue
End With
With myChtObj.Chart
.ChartType = xlLineMarkers
.HasTitle = True
.ChartTitle.Characters.Text = myChtTitle
.HasLegend = False
With .Axes(xlValue, xlPrimary)
.HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text =
myAxisTitle ~Object doesn't support this property or method
End With
With .Axes(xlCategory, xlPrimary)
.HasTitle = False
With .TickLabels
.Alignment = xlCenter
.Offset = 100
.ReadingOrder = xlContext
.Orientation = 45
End With
End With
With .PlotArea
.Left = 1
.Top = 24
.Width = 354
.Height = 186
End With
End With
End If

' Save chart as GIF
Fname = ThisWorkbook.Path & Application.PathSeparator & "temp.gif"
~Type Mismatch
myChtObj.Chart.Export Filename:=Fname, FilterName:="GIF"

' Load Image to Form
Image1.Picture = LoadPicture(Fname)



I would appreciate any help




All times are GMT +1. The time now is 05:23 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com