【问题标题】:VB.Net Office Spell Check issueVB.Net Office 拼写检查问题
【发布时间】:2011-03-18 01:37:46
【问题描述】:

我有一个网络部署的 .Net 3.5 Windows Form VB.Net 应用程序,它引用了 Microsoft Office 12.0 库 dll。

截至上周,以下代码正常运行,但是,运营团队升级了每个人的 Office(不是重大升级,只是小升级)。基本上,当拼写检查器运行时,它隐藏在 VB.Net 应用程序后面,并且看起来应用程序现在已冻结。当我查看任务管理器时,我看到 Office 的实例正在运行,当我将该程序设置到前面(在任务管理器中)时,我看到拼写检查框并且可以继续执行。我不确定在我的代码中我缺少什么来设置拼写检查框的优先级,以便它位于应用程序的顶部。

截至今天,我使用的是 12.0 库的 2.0.5 版本,但最初我使用的是该 dll 的 1.2.x。但是升级到最新版本什么也没做。我得到了同样的结果。

我还应该注意,我查看了第 3 方拼写检查器(组件一),并且需要在字典中进行自定义。所以我希望有一种方法可以让我像上周一样使用 Office!

欢迎任何想法或建议:

'Check subject line
If Me.txtSubject.TextLength > 0 And Me.txtSubject.Enabled = True Then
    Dim objWA As New Word.Application

    'objWA.Visible = False
    Dim objWD As Word.Document = objWA.Documents.Add
    'objWA.WindowState = Word.WdWindowState.wdWindowStateNormal
    Try
        With objWD
            .Range.Text = Me.txtSubject.Text
            .Activate()
            .CheckSpelling()
            .Content.Copy()

            If Clipboard.GetDataObject.GetDataPresent(DataFormats.Text) Then
                Me.txtSubject.Text = CType(Clipboard.GetDataObject.GetData(DataFormats.Text), String)
            End If

            .Saved = True
            objWA.Visible = False
            .Close(Word.WdSaveOptions.wdDoNotSaveChanges)
        End With

        'Application.DoEvents()
        objWA.Quit()
        objWA.Visible = False   'need this to get around the save prompt pop up

    Catch compEx As COMException
        MessageBox.Show("Microsoft Word must be installed for Spell Check to run.", "CustomerServiceTool", MessageBoxButtons.OK, MessageBoxIcon.Error)

    Catch ex As Exception
        If Err.Number = 5 Then  'bypass Clipboard operation failed errors
            objWA.Visible = False
            objWA.Quit()
        Else
            MessageBox.Show(Err.Description, "CustomerServiceTool", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End If
    Finally
        objWD = Nothing
        objWA = Nothing
    End Try


End If

'Check Message body
If Me.txtResponse.Text.Length > 0 Then
    Dim objWA1 As New Word.Application
    ' Dim objWA1 As Word._Application
    ' objWA1 = New Word.Application

    objWA1.Visible = False
    Dim objWD1 As Word.Document = objWA1.Documents.Add

    Try
        objWD1.Activate()
        With objWD1
            .Range.Text = Me.txtResponse.Text

            .CheckSpelling()
            .Content.Copy()

            If Clipboard.GetDataObject.GetDataPresent(DataFormats.Text) Then
                Me.txtResponse.Text = CType(Clipboard.GetDataObject.GetData(DataFormats.Text), String)
            End If

            .Saved = True
            objWA1.Visible = False
            .Close(Word.WdSaveOptions.wdDoNotSaveChanges)
        End With


        'Application.DoEvents()
        objWA1.Quit()
        MessageBox.Show("The spelling check is complete.", "CustomerServiceTool", MessageBoxButtons.OK, MessageBoxIcon.Information)

    Catch compEx As COMException
        MessageBox.Show("Microsoft Word must be installed for Spell Check to run.", "CustomerServiceTool", MessageBoxButtons.OK, MessageBoxIcon.Error)

    Catch ex As Exception
        If Err.Number = 5 Then  'bypass Clipboard operation failed errors
            objWA1.Visible = False
            objWA1.Quit()
        Else
            MessageBox.Show(Err.Description, "ASHLinkCST", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End If
    Finally
        objWD1 = Nothing
        objWA1 = Nothing
    End Try

End If

【问题讨论】:

    标签: .net vb.net


    【解决方案1】:

    这是其中之一,管理员与开发者之谜...网络管理员说他们什么也没做,而开发者说他在 3 年内没有更改代码...

    所以...我们最终购买了一个独立于办公室的第 3 方组件...这似乎解决了问题。

    【讨论】:

      猜你喜欢
      • 2023-03-07
      • 2011-02-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-10
      • 2011-02-02
      • 1970-01-01
      相关资源
      最近更新 更多