Click here to Skip to main content
15,905,238 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
VB.NET
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim proc As New Process()
        With proc.StartInfo
            .Arguments = " Acrobe Reader"
            .UseShellExecute = True
            .WindowStyle = ProcessWindowStyle.Maximized
            .WorkingDirectory = "C:\Program Files\Adobe\Reader 9.0\Reader\" '<----- Set Acrobat Install Path
            .FileName = "AcroRd32.exe" '<----- Set Acrobat Exe Name
        End With
        proc.Start()
        proc.Close()
        proc.Dispose()
    End Sub
    Private Sub SpellOrGrammarCheck(ByVal blnSpellOnly As Boolean)
        Try
            Dim objWord As Object
            Dim objTempDoc As Object
            Dim iData As IDataObject
            If Textbox1.Text = "" Then
                Exit Sub
            End If
            objWord = New WordApplication1.Form1()
''Its getting error here
            objTempDoc = objWord.Documents.Add
            objWord.Visible = False
            objWord.WindowState = 0
            objWord.Top = -3000
            Clipboard.SetDataObject(Textbox1.Text)
            With objTempDoc
                .Content.Paste()
                .Activate()
                If blnSpellOnly Then
                    .CheckSpelling()
                Else
                    .CheckGrammar()
                End If
                .Content.Copy()
                iData = Clipboard.GetDataObject
                If iData.GetDataPresent(DataFormats.Text) Then
                    Textbox1.Text = CType(iData.GetData(DataFormats.Text), _
                        String)
                End If
                .Saved = True
                .Close()
            End With
            objWord.Quit()
            MessageBox.Show("The spelling check is complete.", _
                "Spell Checker", MessageBoxButtons.OK, _
                MessageBoxIcon.Information)
        Catch COMExcep As Runtime.InteropServices.COMException
            MessageBox.Show( _
                "Microsoft Word must be installed for Spell/Grammar Check " _
                & "to run.", "Spell Checker")
        Catch Excep As Exception
            MessageBox.Show("An error has occurred.", "Spell Checker")
        End Try
    End Sub
    Private Sub btnSpellCheck_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles btnSpellCheck.Click
        SpellOrGrammarCheck(True)
    End Sub
    Private Sub btnGrammarCheck_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles btnGrammarCheck.Click
        SpellOrGrammarCheck(False)
    End Sub
End Class
Posted
Updated 15-Feb-10 3:22am
v6

HELP DESK is online.
Please specify the nature of the error.

... Waiting for response.
 
Share this answer
 
lovely999 wrote:
Someone, please help me.


Why do you keep asking this question when you do not tell us what the problem is? Nobody here can guess what is going wrong.
 
Share this answer
 
Ok,
Let's guess what is wrong!

Maybe it won't compile because objWord = New WordApplication1.Form1() isn't the way that a word automation object is created.

Even if you fixed that I think there will be many other errors as you have not dimensioned the variables correctly.

Use
Dim objWord as Word.Application

not
Dim objWord as Object

Probably the best thing you can do is take at look at this code sample Spell Check from VB.Net[^] which does exactly what you want. You'll notice that there is no need to use the clipboard to transfer data from a textbox into the word document.

Alan.
 
Share this answer
 
lovely999 wrote:
Its getting error here


So fix the error and everything will be fine!

Did you read my previous entry? You need to explain what the error is; we have no way of guessing what is going wrong in your code.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900