replace

C

carl

guys
I'm running Word97 and the VB library is
missing "Replace". Since it is a work computer I can't
change or add to the VB library.
This there a work around? The specific code i need to run
is
strCmd = Replace(strCmd, "%1", strDoc)
which comes up with "sub or function not defined" ...
the 'Replace' is highlighted
 
D

DA

The following will do the same, although I replaced your
search string with a variable rather than a hardcoded
string.

Dennis

-------------
str2Find = "%1"
Do While InStr(strCmd, str2Find) <> 0
strCmd = Left(strCmd, (InStr(strCmd, str2Find) - 1)) + _
strDOC + Right(strCmd, Len(strCmd) - _
InStr(strCmd, str2Find) - Len(str2Find) + 1)
Loop
 
J

Jean-Guy Marcil

Bonjour,

Dans son message, < carl > écrivait :
In this message, < carl > wrote:

|| guys
|| I'm running Word97 and the VB library is
|| missing "Replace". Since it is a work computer I can't
|| change or add to the VB library.
|| This there a work around? The specific code i need to run
|| is
|| strCmd = Replace(strCmd, "%1", strDoc)
|| which comes up with "sub or function not defined" ...
|| the 'Replace' is highlighted

The Replace Function was not included in the Office 97 libraries (Except in
Excel where it is not the usual VB Replace, but the Excel Replace).

You can use this function:
'_______________________________________
Public Function ReplaceStr(ByVal MainString As String, _
ByVal RepThis As String, _
ByVal WithThis As String) As String

Dim i As Long

While Left(MainString, Len(RepThis)) = RepThis
MainString = WithThis & _
Mid(MainString, Len(RepThis) + 1)
Wend

While InStr(2, MainString, RepThis) > 0
i = InStr(2, MainString, RepThis)
MainString = Left(MainString, i - 1) _
& WithThis & Mid(MainString, i + Len(RepThis))
Wend

ReplaceStr = MainString

End Function
'_______________________________________

Call it like:

'_______________________________________
Sub TestReplace()

Dim BigString As String
Dim NewBigString As String

BigString = "Put as much text as you want here..."
NewBigString = ReplaceStr(BigString, "Put", "Type")

End Sub
'_______________________________________

or, in your case
'_______________________________________
strCmd = ReplaceStr(strCmd, "%1", strDoc)
'_______________________________________

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top