PC Review


Reply
Thread Tools Rate Thread

2003 macro generates compiler error on 2007

 
 
KenInPortland
Guest
Posts: n/a
 
      29th Aug 2008
The following macro works fine in Excel 2003 but generates a compiler error
on 2007. Any ideas or direction?

Sub WhoRang()
Dim ButtonLabel As String
Dim First6chars As String
Dim RowNum As String
ButtonLabel = Application.Caller
' 2007 compiler error occurs here
First6chars =
Left(ActiveSheet.Shapes(ButtonLabel).TextFrame.Characters.Text, 6)
RowNum = Range("N1:N32").Find(What:=First6chars).Row
Application.GoTo Range(Range("O" & RowNum).Value)
End Sub
 
Reply With Quote
 
 
 
 
JLatham
Guest
Posts: n/a
 
      29th Aug 2008
My recommendation is to record a macro in 2007 as you go through that process
manually and compare what is recorded to the 2003 code.

There are some strange things going on with command buttons on worksheets
created in earlier versions of Excel. I haven't been able to pin it down. I
had a request recently to fix a package that I created for AT&T that was
originally created in Excel 97 and worked faithfully right up until it was
used in 2007. Believe it or not, I ran into failures on the sheet that
seemed to actually be related to either the location or size of the button(s)
involved. I came up with a work-around by taking the coward's path of not
recreating all the buttons on the sheet that I had been, and was lucky in
that the ones that did have to be recreated were all handled properly. The
ones that caused failure were created and manipulated in exactly the same way
except that they were larger sized, had more text in them and were of course,
in different locations on the sheet.

In your case we probably need to drag out the Excel 2007 Object Model
http://msdn.microsoft.com/en-us/library/bb332345.aspx
and make sure that your reference to the shape and its properties is
completely accurate and that Excel 2007 understands it all. I presume that
the button has at least 6 characters in its caption. And that leads to an
idea that you may need to be referencing the .Caption instead of
..TextFrame.Characters.Text ??

This link, to information about the Shapes Object may help you:
http://msdn.microsoft.com/en-us/library/bb178401.aspx

"KenInPortland" wrote:

> The following macro works fine in Excel 2003 but generates a compiler error
> on 2007. Any ideas or direction?
>
> Sub WhoRang()
> Dim ButtonLabel As String
> Dim First6chars As String
> Dim RowNum As String
> ButtonLabel = Application.Caller
> ' 2007 compiler error occurs here
> First6chars =
> Left(ActiveSheet.Shapes(ButtonLabel).TextFrame.Characters.Text, 6)
> RowNum = Range("N1:N32").Find(What:=First6chars).Row
> Application.GoTo Range(Range("O" & RowNum).Value)
> End Sub

 
Reply With Quote
 
KenInPortland
Guest
Posts: n/a
 
      2nd Sep 2008
Thanks for your help, JL
I investigated the .Caption property, but it did not fix the 2007
compilation problem, but your point is well taken about the .Text property
and I did leave the change in. It turned out the problem was the LEN
function in my procedure. Apparently 2007 requires the full specification of
"VBA.Strings.Len()" or it gets confused with LEN properties.

"JLatham" wrote:

> My recommendation is to record a macro in 2007 as you go through that process
> manually and compare what is recorded to the 2003 code.
>
> There are some strange things going on with command buttons on worksheets
> created in earlier versions of Excel. I haven't been able to pin it down. I
> had a request recently to fix a package that I created for AT&T that was
> originally created in Excel 97 and worked faithfully right up until it was
> used in 2007. Believe it or not, I ran into failures on the sheet that
> seemed to actually be related to either the location or size of the button(s)
> involved. I came up with a work-around by taking the coward's path of not
> recreating all the buttons on the sheet that I had been, and was lucky in
> that the ones that did have to be recreated were all handled properly. The
> ones that caused failure were created and manipulated in exactly the same way
> except that they were larger sized, had more text in them and were of course,
> in different locations on the sheet.
>
> In your case we probably need to drag out the Excel 2007 Object Model
> http://msdn.microsoft.com/en-us/library/bb332345.aspx
> and make sure that your reference to the shape and its properties is
> completely accurate and that Excel 2007 understands it all. I presume that
> the button has at least 6 characters in its caption. And that leads to an
> idea that you may need to be referencing the .Caption instead of
> .TextFrame.Characters.Text ??
>
> This link, to information about the Shapes Object may help you:
> http://msdn.microsoft.com/en-us/library/bb178401.aspx
>
> "KenInPortland" wrote:
>
> > The following macro works fine in Excel 2003 but generates a compiler error
> > on 2007. Any ideas or direction?
> >
> > Sub WhoRang()
> > Dim ButtonLabel As String
> > Dim First6chars As String
> > Dim RowNum As String
> > ButtonLabel = Application.Caller
> > ' 2007 compiler error occurs here
> > First6chars =
> > Left(ActiveSheet.Shapes(ButtonLabel).TextFrame.Characters.Text, 6)
> > RowNum = Range("N1:N32").Find(What:=First6chars).Row
> > Application.GoTo Range(Range("O" & RowNum).Value)
> > End Sub

 
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
Re: Macro Recording generates an error message Nick Hodge Microsoft Excel Crashes 1 13th Dec 2006 07:34 AM
Outlook.Application generates compiler error Christopher Glaeser Microsoft Access Form Coding 3 25th Apr 2006 07:14 PM
Recorded Macro to Set page breaks generates error. =?Utf-8?B?SmFyZWQ=?= Microsoft Excel Programming 13 9th Dec 2004 06:45 AM
Macro generates error 1004 Brian Microsoft Excel Worksheet Functions 3 7th Aug 2004 05:19 AM
fatal error C1001: INTERNAL COMPILER ERROR (compiler file 'f:\vs70builds\3077\vc\Compiler\Utc\src\P2\main.c', line 148) PufferFish Microsoft VC .NET 10 6th Aug 2004 10:33 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:38 PM.