I added the StripCharsfunction to this module; it is called throughout the add-in to remove
various characters and spaces from control names during renaming, so as prevent problems when
the controls are referenced in code. I modified the standard template AddInErrprocedure
slightly; it creates a message box string that is called from error handlers in the add-in. The
SharedCode module that contains these procedures is listed next:
Option Explicit
Public Function StripChars(strText _
As String) As String
Strips a variety of non-alphanumeric characters from a text string.
On Error GoTo ErrorHandler
Dim strTestString As String
Dim strTestChar As String
Dim lngFound As Long
Dim i As Integer
Dim strStripChars As String
strStripChars = “ `~!@#$%^&*()-_=+[{]};:’,<.>/?” _
& Chr$(34) & Chr$(13) & Chr$(10)
strTestString = strText
i = 1
Do While i <= Len(strTestString)
Find a strippable character.
strTestChar = Mid$(strTestString, i, 1)
lngFound = InStr(strStripChars, strTestChar)
If lngFound > 0 Then
strTestString = Left(strTestString, i - 1) _
& Mid(strTestString, i + 1)
Else
i = i + 1
End If
Loop
StripChars = strTestString
ErrorHandlerExit:
Exit Function
ErrorHandler:
AddInErr Err
Resume ErrorHandlerExit
End Function
Creating COM Add-ins with Visual Basic 6 13