Welcome to MacForumz.com!
FAQFAQ      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Compile Error: Sub or Function not defined

 
   Macintosh computer (Home) -> Excel RSS
Next:  KB888619 problem  
Author Message
cstordalen

External


Since: Jan 13, 2006
Posts: 1



(Msg. 1) Posted: Fri Jan 13, 2006 3:51 pm
Post subject: Compile Error: Sub or Function not defined
Archived from groups: microsoft>public>mac>office>excel (more info?)

Greetings -

A developer in a central office at the university I work at developed a
one-file Excel solution to automatically cleanup submitted data from
around our university for incorporation into a central system. This
file is built in Excel on Windows. I am not a macros/VBA guy and so am
lost as to how to hopefully resolve the issue we are having with the
file.

Launching the file results in a message stating that Macros are
required and asking if they should be turned on. When selecting this
option a window appears with the message "Compile Error: Sub or
Function not defined".

The code in the VBA editor that appears after selecting 'OK' from the
message is:

Function doubleQuotes(strInput)
' also trims extra spaces from start and end
' also escapes special characters like "_" and "&"
Dim strResults As String
strResults = Replace(Trim(strInput), "'", "''")
strResults = Replace(strResults, "_", "\_")
strResults = Replace(strResults, "&", "\&")
doubleQuotes = strResults
End Function

I read in another thread that the Visual Basic in Office 2004 has not
kept pace with the updates to the Windows version. Could this be the
cause - the Mac version doesn't recognize this/these commands?

It sounds as though we will not get help in making this file
Mac-friendly from the Windows developer who put it together so any help
from this group would be most appreciated.

Regards -

Christopher

 >> Stay informed about: Compile Error: Sub or Function not defined 
Back to top
Login to vote
JE McGimpsey

External


Since: Mar 07, 2004
Posts: 3828



(Msg. 2) Posted: Fri Jan 13, 2006 5:28 pm
Post subject: Re: Compile Error: Sub or Function not defined [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article <1137196265.245495.80800 RemoveThis @g14g2000cwa.googlegroups.com>,
"cstordalen@yahoo.com" <cstordalen RemoveThis @yahoo.com> wrote:

> Launching the file results in a message stating that Macros are
> required and asking if they should be turned on. When selecting this
> option a window appears with the message "Compile Error: Sub or
> Function not defined".
>
> The code in the VBA editor that appears after selecting 'OK' from the
> message is:
>
> Function doubleQuotes(strInput)
> ' also trims extra spaces from start and end
> ' also escapes special characters like "_" and "&"
> Dim strResults As String
> strResults = Replace(Trim(strInput), "'", "''")
> strResults = Replace(strResults, "_", "\_")
> strResults = Replace(strResults, "&", "\&")
> doubleQuotes = strResults
> End Function
>
> I read in another thread that the Visual Basic in Office 2004 has not
> kept pace with the updates to the Windows version. Could this be the
> cause - the Mac version doesn't recognize this/these commands?

That's exactly it. Replace() was introduced in VBA6.

Fortunately if you replace each instance of

Replace(

with

Application.Substitute(

the code will work fine in MacXL (and WinXL97).

For my applications, I normally write my own Replace() code and
conditionally compile it:

#If Mac Then
Public Function Replace(ByRef Text As String, _
ByRef sOld As String, ByRef sNew As String, _
Optional ByVal Start As Long = 1, _
Optional ByVal Count As Long = 2147483647, _
Optional ByVal Compare As Integer = vbBinaryCompare _
) As String
'lots of code here
End Function
#End If

That way, WinXL200x will ignore my Replace() function and use the
built-in one, and Macs will use mine.

 >> Stay informed about: Compile Error: Sub or Function not defined 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Compile error: Sub or Function not found - I'm trying to write some macros using VBA in Excel and keep getting compile errors with "Sub or Function not found" using very simple Excel (worksheet) functions. The help files seem to indicate that these functions should be available to VBA. ...

A function to display a formula that's defined within anot.. - I need to discover whether there is a function which will retrieve the FORMULA EXPRESSION that's held within another cell - for example, I'd like to be able to write this expression in a cell: =GETFORMULA(E4) //this would display the formula that's..

Mac VBA compile error - Help! - Hopefully, someone has seen this & knows a work-around - it's making me crazy. I don't have a lot of experience writing VBA code for this platform. I'm developing a set of macros (on Win/XP) and testing them on Macs. When I open the workbook, I try ...

Compile Error Message - I have recently installed the latest Mac Office 2004 update. Now, whenever I try to exit from Excel I get the following message: Compile error in hidden module: AutoExec The error does not seem to compromise the file that I am working on, but I..

Compile error: Automation error - Greetings, I have a very small excel spreadsheet that was created on a PC but many users run on a mac. The error occurs on the following: Sub Show() emails.show end sub That's it. These users get a "Compile Error: Automation error" error. ...
   Macintosh computer (Home) -> Excel All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]