Replace() Function -- Syntax Error

G

Gray M. Strickland

Why doesn't:
--Dim currname As String
--currname = ActiveDocument.FullName
--replace(currname," ","%20",1,-1,1)
work? (at least in Word 2003's implementation of VBA)? I get, "Compile
Error. Expected =" I think I am faithfully following the syntax described in
the Word/VB help file (see end of this posting), but obviously I am not if I
get an error message. My goal is to create a string variable equal to the
complete filename but with any spaces replaced with "%20" (minus the
quotes). The result will be a click-able hyperlink when pasted into an
email.



==================================
FROM WORD/VBA HELP FILE

Replace Function
Description -- Returns a string in which a specified substring has been
replaced with another substring a specified number of times.
Syntax -- Replace(expression, find, replace[, start[, count[, compare]]])
Where:
-- expression = String expression containing substring to replace.
-- find = Substring being searched for.
-- replace = Replacement substring.
-- start (Optional) = Position within expression where substring search
is to begin. If omitted, 1 is assumed.
-- count (Optional) = Number of substring substitutions to perform. If
omitted, the default value is -1, which means make all possible
substitutions.
-- compare (Optional) = Numeric value indicating the kind of comparison
to use when evaluating substrings where:
== vbUseCompareOption -1 Performs a comparison using the setting of the
Option Compare statement.
== vbBinaryCompare 0 Performs a binary comparison.
== vbTextCompare 1 Performs a textual comparison.
== vbDatabaseCompare 2 Microsoft Access only. Performs a comparison
based on information in your database.
 
G

Greg Maxey

Gray,

You need something like:

Dim currname As String
Dim newname As String
currname = ActiveDocument.FullName
newname = Replace(currname, " ", "20%")
 

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