[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 289
  • Last Modified:

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.

0
GrayStrickland
Asked:
GrayStrickland
  • 2
2 Solutions
 
ColosseoCommented:
Hi

I think it is just that you need to return the replace to something like this

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

the replace function returns the new string back to the currname variable

HTH

Scott

0
 
[ fanpages ]IT Services ConsultantCommented:
This works for me...

? Replace(ActiveDocument.FullName, " ", "%20")

What do you see that is unexpected?

BFN,

fp.
0
 
ColosseoCommented:
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
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now