Results 1 to 2 of 2
  1. #1
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Bug in AddFromString???? (Word VBA)

    The code below is operating on a Userform in Word 2002.

    Prior to the AddFromString, there are no lines of code for the Userform, I confirmed this by stopping the macro just before the AddFromString.

    Using Debug.Print, I can see that the last characters in strBuffer are "End Sub".

    However, after executing the AddFromString, I find that a blank line and a line with only () have been added by AddFromString

    So far, I've seen this with only one Userform. I will try others. Last, I will try AddFromFile.

    I have used this code with 15 Userforms. Only 1 UserForm has exhibited the problem.

    Anybody see this before? I found nothing in the KB or MSDN.
    <pre> With .CodeModule
    If .CountOfDeclarationLines <> 0 Then
    .DeleteLines 1, .CountOfDeclarationLines
    End If
    If .CountOfLines <> 0 Then
    .DeleteLines 1, .CountOfLines
    End If
    .AddFromString strBuffer
    End With
    </pre>


  2. #2
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Bug in AddFromString???? (Word VBA)

    I have isolated the problem. Appears to be a bug in AddFromString. Using

    <pre> If .CountOfLines <> 0 Then
    .DeleteLines 1, .CountOfLines
    End If
    strNewCode = Trim$(strNewCode)
    .AddFromString strNewCode
    </pre>


    The extraneous () appears in one module (or userform) per project.

    The problem does not occur if I use InsertLines instead of AddFromString.
    <pre> If .CountOfLines <> 0 Then
    .DeleteLines 1, .CountOfLines
    End If
    strNewCode = Trim$(strNewCode)
    .InsertLines 1, strNewCode
    </pre>

    According to the Help for AddFromString, since I had already deleted all the lines, the string should have been inserted at the end of the module. So InsertLines, as used above, and AddFromString would be expected to produce identical results.

    I guess that AddFromString is getting confused by not finding a procedure in particular cases and is inserting the () it would have found in a, say, Sub statement. But why only once per project? Seems like a strange bug.

Posting Permissions

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