Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / April 2005

Tip: Looking for answers? Try searching our database.

Replace() Function -- Syntax Error

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Gray M. Strickland - 27 Apr 2005 00:07 GMT
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.
Greg Maxey - 27 Apr 2005 00:21 GMT
Gray,

You need something like:

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

Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

> Why doesn't:
> --Dim currname As String
[quoted text clipped - 32 lines]
>    == vbDatabaseCompare 2 Microsoft Access only. Performs a comparison
> based on information in your database.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.