Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Christchurch, New Zealand
    Posts
    250
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Microsoft Word - Replace function returns compile error: expected array

    Hi All,

    I have a simple piece of code in a module on my Normal template:

    Code:
    Sub SearchString()
           Dim txt As String
           Dim newtxt As String
           txt = "Designation1/Designation2"
           newtxt = Replace(txt, "/", vbCr)
           Selection.TypeText Text:=newtxt
        
    End Sub
    Works beautifully. BUT, take this same code into another module on another template (AuthorDesignation has already been defined and is a simple string variable) and I get a compile error: expected array. This happens in Word 2010 and Word 2003. Try as I might, I cannot see a difference between the two.

    Code:
    If AuthorDesignation <> "" Then
        
               AuthorDesignation = Replace(AuthorDesignation, "/", vbCr)   'if the designation goes on to two lines
               Selection.TypeText Text:=vbCr & AuthorDesignation    
    End If
    I'm not trying to deal with an array at all - I just want to remove the character / from the text.

    Any help would be appreciated.

    Thank you.

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts
    Do you have any other Replace method/function defined in the scope of that procedure? It could be furnished through an external library (e.g., listed under References) or be a separate function in your project.

  3. #3
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Christchurch, New Zealand
    Posts
    250
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thank you so much. There was a string variable named Replace. Once I changed this to strReplace everything worked perfectly! Pity the error message didn't just say I had an ambiguous name or something understandable (to me anyway ).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •