[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
Re: conversion from type 'Range' to type 'String' not valid
try this:
vb Code:
Dim strResult As String = Strings.Left(objDoc.Content.Text, Len(objDoc.Content.Text) - 1)
Re: conversion from type 'Range' to type 'String' not valid
Thank you paul, I will try that and let you know.
Re: conversion from type 'Range' to type 'String' not valid
Yes Paul, that worked wonderfully. Sorry for the late response.