PC Review


Reply
Thread Tools Rate Thread

Compile error in 2003

 
 
Lee
Guest
Posts: n/a
 
      27th May 2009
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
 
Reply With Quote
 
 
 
 
Bernie Deitrick
Guest
Posts: n/a
 
      27th May 2009
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


"Lee" <(E-Mail Removed)> wrote in message
newsBD70B0F-8873-4E75-A743-(E-Mail Removed)...
> 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



 
Reply With Quote
 
Chip Pearson
Guest
Posts: n/a
 
      27th May 2009

>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)



On Wed, 27 May 2009 14:42:56 -0400, "Bernie Deitrick" <deitbe @
consumer dot org> wrote:

>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
>
>
>"Lee" <(E-Mail Removed)> wrote in message
>newsBD70B0F-8873-4E75-A743-(E-Mail Removed)...
>> 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

>

 
Reply With Quote
 
Chip Pearson
Guest
Posts: n/a
 
      27th May 2009

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)




On Wed, 27 May 2009 10:31:01 -0700, Lee
<(E-Mail Removed)> wrote:

>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

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Compile Error in Excel 2003 =?Utf-8?B?QmVuVg==?= Microsoft Excel Crashes 3 6th Nov 2009 05:05 PM
Vs 2003.Net Compile Error Jason Microsoft VB .NET 1 12th May 2006 08:46 PM
excel 2003 - error in starting the program compile error in AutoExecNew Sam Microsoft Excel Misc 3 13th Feb 2006 03:27 PM
When I open Word (2003) I get an error msg - Compile error in hid. =?Utf-8?B?U3RldmVX?= Microsoft Word Document Management 1 18th Oct 2004 03:19 AM
excel 2003 error>> compile error in hidden module: ThisWorkbook clayton Microsoft Excel Misc 4 22nd Jun 2004 02:02 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:09 PM.