Compile error in 2003


L

Lee

The following code fails to compile in Excel 2003 because it uses methods
that are new to Excel 2007. Is there any way around this problem or do I
need to create a separate program for Excel 2003 and 2007?

'The code to add a tile for the chart and axes is different for Excel
2003 and 2007
If Application.Version = "11.0" Then
With ActiveChart
'Excel 2003 code
.HasTitle = True
.ChartTitle.Characters.Text = strTitle + Chr(10) + strSubTitle
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text =
strXAxis
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = strYAxis
End With
ElseIf Application.Version = "12.0" Then
With ActiveChart
'Excel 2007 code
.SetElement (msoElementChartTitleAboveChart)
.ChartTitle.Text = strTitle + Chr(10) + strSubTitle
.SetElement (msoElementPrimaryCategoryAxisTitleAdjacentToAxis)
.Axes(xlCategory, xlPrimary).AxisTitle.Text = strXAxis
.SetElement (msoElementPrimaryValueAxisTitleRotated)
.Axes(xlValue, xlPrimary).AxisTitle.Text = "y-axis stryaxis"
End With
End If
 
Ad

Advertisements

B

Bernie Deitrick

Lee,

I think you can use this for conditional compiling...the #s are required.

Sub Test()
2007Ver = Val(Application.Version) >= 11
#If 2007Ver Then
'2007 code here
#Else
'2003 code here
#End If
End Sub

HTH,
Bernie
MS Excel MVP
 
C

Chip Pearson

2007Ver = Val(Application.Version) >= 11
#If 2007Ver Then

That won't work for so many reasons.....

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)
 
Ad

Advertisements

C

Chip Pearson

You can use conditional compilation. E.g., at the top of your module,

#Const XL2007 = True ' Or False

' in the procedure code

#If XL2007 Then
' your code for Excel 2007
#Else
' your code for Excel 2003
#End If

You'll have to set the #Const value for XL2007 manually -- there is no
way to automate it.

As an alternative, you can use CallByName. E.g.,

If CInt(Application.Version) > 11 Then
' Excel 2007
CallByName ActiveChart,"HasTitle",VbLet,True
' other calls to CallByName for other properties
Else
' Excel 2003
CallByName ActiveChart,"ChartTitle",VbLet, "your title here"
' other calls to CallByName for other properties.
End If

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top