Link to home
Start Free TrialLog in
Avatar of GrayStrickland
GrayStrickland

asked on

Replace() -- Syntax Error

Why doesnt':
--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.

ASKER CERTIFIED SOLUTION
Avatar of Colosseo
Colosseo
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of [ fanpages ]
[ fanpages ]

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
As well you can also just use:

Dim currname As String
currname = replace(ActiveDocument.FullName," ","%20",1,-1,1)

Saves a line of code which never hurts :)

Scott