Access VB to Excel VB

ZMAN2

Registered User.
Local time
Today, 04:49
Joined
May 6, 2003
Messages
37
I would like to use the following code in Excel, what changes have to be made for it to work? Thanks in advance.

Code:
Public Function TestCharMatch1(NbrOfChars, StrSearch As String, strFind As String) As String
    'Walks through strFind, NbrofChars at at time, and searches strSearch for a match.
    If NbrOfChars > Len(strFind) Then
        TestCharMatch1 = "ERROR!"
        Exit Function
    End If
    Dim Pos As Integer
    Pos = 1
    Do While Pos <= (Len(strFind) - (NbrOfChars - 1))
        If InStr(StrSearch, Mid(strFind, Pos, NbrOfChars)) > 0 Then
            TestCharMatch1 = "Yes! " & Mid(strFind, Pos, NbrOfChars)
            Exit Do
        Else
            TestCharMatch1 = "Sorry no match!"
        End If
        Pos = Pos + 1
    Loop
End Function
 
Last edited by a moderator:
Thanks.

Thanks for the quick response. :D
 
No probs. As the code deals only with basic VBA Data Types and structural keywords then it can be used in any other application that uses VBA.

If, however, the code were to use objects exclusive to a specific application, then it would require reworking.
 
Related Question

If I store the module in a particular workbook, the function works. Why can't I store the module in PERSONAL.xls and have it available to all workbooks that I use? Let me clarify, I have already saved the module to PERSONAL.xls, but when I open a brand new workbook the function doesn't work (#NAME?). Go figure. The reason I was asking is because you can store a macro in PERSONAL.xls and have it available to all other workbooks, maybe I did something wrong but I thought it should work the same way.
 

Users who are viewing this thread

Back
Top Bottom