Group: microsoft.public.word.vba.general
From: Jay Freedman
Date: Friday, February 29, 2008 6:31 PM
Subject: Re: String manipulation problem

While everything Jean-Guy and fumei have said is true, I'll point out the
immediate misconception in your code:

The variable str (whatever you eventually call it, in view of Jean-Guy's
critique) is declared in the parameter list as a String variable. There is no
such thing as a Chars member of a String (and in fact String is a simple data
type, not an object, so it has no members at all).

To get the I-th character from a string, use the Mid function:

thisChar = Mid(str, I, 1)

Look up this function in the VBA help, along with its friends Left and Right.

On Fri, 29 Feb 2008 07:33:03 -0800, SueP wrote:

>I want a VB function (called from a word macro) that takes a string and I
>want to manipulate each character at a time. I must be doing something stupid:
>
>function Spaces(str As String, len As Integer)
>for I = 1 to len
> thisChar = str.Chars(I)
>next I
>end function
>
>The message I get is Error 424 Object Required. It does not appear to
>recognize str as a string object. HELP?
>

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit.