VS 2010 [RESOLVED] conversion from type 'Range' to type 'String' not valid-VBForums
Results 1 to 4 of 4

Thread: [RESOLVED] conversion from type 'Range' to type 'String' not valid

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,303

    Resolved [RESOLVED] conversion from type 'Range' to type 'String' not valid

    I have the following code to use Words spellcheck feature on a RTB. Once you pick the correct word in the spellcheck box and press change I get the error on th efollwoing line

    strResult = Left(objDoc.Content, Len(objDoc.Content) - 1)

    I tried to use CType() but still complains.

    Code:
    If (Len(t.Text) = 0) Then
                    'nahhhhhhhhhhh
                Else
                    'App.OleRequestPendingTimeout = 999999
                    objWord = CreateObject("word.Application")
                    objWord.Visible = False
                    Select Case objWord.Version
                        'Office 2000, xp, 2k3
                        Case "9.0", "10.0", "11.0", "12.0"
                            objDoc = objWord.Documents.Add(, , 1, True)
                            'Office 97
                        Case Else
                            objDoc = objWord.Documents.Add
                    End Select
    
                    objDoc.Content = t.Text
                    objDoc.CheckSpelling()
                    objWord.Visible = False
                    strResult = Left(objDoc.Content, Len(objDoc.Content) - 1)
                    'correct the carriage returns
                    strResult = Replace(strResult, Chr(13), Chr(13) & Chr(10))
    
                    If t.Text = strResult Then
                        ' There were no spelling errors, so give the user a
                        ' visual signal that something happened
                        MsgBox("The spelling check is complete.", vbInformation + vbOKOnly, "Spelling Complete")
                    End If
                    'Clean up
                    objDoc.Close(False)
                    objDoc = Nothing
                    objWord.Application.Quit(True)
                    objWord = Nothing
    
                    ' Replace the selected text with the corrected text. It's important that
                    ' this be done after the "Clean Up" because otherwise there are problems
                    ' with the screen not repainting
                    t.Text = strResult
                End If

  2. #2
    vb Coda .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    19,091

    Re: conversion from type 'Range' to type 'String' not valid

    try this:

    vb Code:
    1. Dim strResult As String = Strings.Left(objDoc.Content.Text, Len(objDoc.Content.Text) - 1)

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,303

    Re: conversion from type 'Range' to type 'String' not valid

    Thank you paul, I will try that and let you know.

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,303

    Re: conversion from type 'Range' to type 'String' not valid

    Yes Paul, that worked wonderfully. Sorry for the late response.

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.