Results 1 to 2 of 2

Thread: [RESOLVED] Invalid Range value, 2 boxes side by side in quotes

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2006
    Posts
    71

    Resolved [RESOLVED] Invalid Range value, 2 boxes side by side in quotes

    Hello when i run this program it errors at the <<<<<<<<<<<<<<<<<<< statement:
    aword.InsertBefore ("x")
    My help doesnt' seem to be working but when i put the cursor on the aword, it shows 2 small box type characters, side by side in quotes, ie "xx", but the x's are boxes.

    Is there a Range method that could test for a valid character or range value something in VBA like:

    aword.isValidCharacter or aword.inValidRange?

    Thanks very much
    BobK

    Code:
    Sub getLineNum()
    
        'Documents.Open
    
        'These hold the range of the words we are looking at
        Dim aword As Range          'The current word range
        Dim pword As Range          'The previous word range
        Dim sw As String            'Raw word pulled from doc
        Dim Excludes As String      'Words to be excluded
        Dim SingleWord As String
       
        Dim bm   As String
        Dim naddr As String
        Dim xref As String
        Dim rdir As String
        Dim line As String
        Dim impflag As String
        Dim la(100) As String
        Dim line_cnt As Double
        Dim sline As String
            
        Dim ar(20) As String
        Set pword = Nothing
        Dim sText As String, oDoc As Document, sLines() As String, lIndex As Long
        
        Set oDoc = Application.ActiveDocument
        
        sText = oDoc.Range.Text
        sLines = Split(sText, vbCr)
        Dim cc As Integer
        
        For lIndex = 0 To UBound(sLines)
             line = sLines(lIndex)
            'MsgBox (CStr(lIndex) + " " + line)
        Next lIndex
    
        Set oDoc = Nothing
        
        For Each aword In ActiveDocument.Words
            
           'cc = aword.Information(wdFirstCharacterLineNumber)
            
            sw = Trim(LCase(aword))
            
           'If sw = "callable" Then
               'MsgBox (aword.Text)
           'End If
           
           If sw = vbCr Or sw = vbLf Or sw = vbCrLf Then
           Else
              aword.InsertBefore ("x") <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
           End If
           
            If sw = vbCr Or sw = vbLf Or sw = vbCrLf Then
               Set pword = aword
               line_cnt = line_cnt + 1
               sline = CStr(line_cnt)
              'aword.InsertAfter (sline + " ")
               bm = "b" + sline
               With ActiveDocument.Bookmarks
                   .Add bm, aword
                    bm = ""
               End With
            End If
        
         Next aword
     
        'ActiveDocument.Save '(wdSaveChanges)
        'ActiveDocument.Close
      
         Set aword = Nothing
         Set pword = Nothing
     
     End Sub

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Apr 2006
    Posts
    71

    Re: Invalid Range value, 2 boxes side by side in quotes

    found it

    For Each aword In ActiveDocument.Words

    'cc = aword.Information(wdFirstCharacterLineNumber)

    sw = Trim(LCase(aword))

    'If sw = "callable" Then
    'MsgBox (aword.Text)
    'End If

    If (Not aword.Information(wdWithInTable)) Then <<<<<<<<<<<<
    aword.InsertBefore ("x")
    End If


    If sw = vbCr Or sw = vbLf Or sw = vbCrLf Then
    Set pword = aword
    line_cnt = line_cnt + 1
    sline = CStr(line_cnt)
    aword.InsertAfter (sline + " ")
    bm = "b" + sline
    With ActiveDocument.Bookmarks
    .Add bm, aword
    bm = ""
    End With
    End If

    Next aword

Posting Permissions

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



Click Here to Expand Forum to Full Width