Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
I am having difficulty getting VB script to work to fast-change a particular chart (exactly how you would by pressing the fast-change button). I got the idea from a previous post on the subject here, but I need to flip between at least 3 chart types.
Here is my macro code. I have attached it to a button. The first part works, so if the chart is currently a line chart, it changes to a bar chart. It doesn't do anything further. I have also tried nesting IF...ELSE IF statements but it doesn't work either. Any ideas?
sub Set1stChartType
set chart = ActiveDocument.GetSheetObject("CH35")
intObjectType = chart.GetObjectType
if intObjectType = 15 then 'is currently a line chart
chart.SetChartType 0
end if
if intObjectType = 0 then 'is currently a line chart
chart.SetChartType 1
end if
if intObjectType = 1 then 'is currently a pie chart
chart.SetChartType 15
end if
end sub
Hi,
I suppose you are missing the ActiveDocument.GetSheetObject("CH196").SetChartType XXX
I use the following macro:
sub SetChartType_Freq
set chart = ActiveDocument.GetSheetObject("CH178")
intObjectType = chart.GetObjectType
if intObjectType = 15 then 'is currently a Bar chart
chart.SetChartType 0
ActiveDocument.GetSheetObject("CH196").SetChartType 0
else
chart.SetChartType 4
ActiveDocument.GetSheetObject("CH196").SetChartType 4
end if
'0=Bar
'1=Pie
'2=Pivot
'3=Scatter
'4=Line
'5=Straight Table
'6=Combo
'7=Radar
'8=Gauge
'9=Grid
'10=Block
'11=Funnel
end sub
Thanks for the assistance, your code works great (I realise I left out those lines). However I try to modify it in order to evaluate 3 different charts, and it fails to do anything at all. I'm sure it's because I'm unfamiliar with VBScript syntax. Here it is:
sub SetChartType_Freq
set chart = ActiveDocument.GetSheetObject("CH35")
intObjectType = chart.GetObjectType
if intObjectType = 15 then 'is currently a Bar chart
chart.SetChartType 0
ActiveDocument.GetSheetObject("CH35").SetChartType 0
else
if intObjectType = 0 then
chart.SetChartType 4
ActiveDocument.GetSheetObject("CH35").SetChartType 4
else
if intObjectType = 4 then
chart.SetChartType 15
ActiveDocument.GetSheetObject("CH35").SetChartType 15
end if
end if
end if
end sub
Hi,
you could add a msgbox to 'debug', msgbox intObjectType, to see if the values are correct (after you have to remove the msgbox).
So, after you find the correct intObjectType, you have to define the fast change you need