我有一個Network Deployed .Net 3.5 Windows Form VB.Net應用程序引用了Microsof Office 12.0 Library dll。VB.Net Office拼寫檢查問題
截至上週,以下代碼正在運行,但操作團隊升級了所有人的Office(不是主要升級,只是小幅升級)。基本上,當拼寫檢查器運行時,它隱藏在VB.Net應用程序後面,看起來應用程序現在被凍結。當我看到任務管理器時,我看到Office正在運行的實例,並且當我將該程序設置在前面(在任務管理器中)時,我看到了「拼寫檢查」框並可以繼續。我不確定我的代碼中缺少的是設置拼寫檢查框的優先級,以便它位於應用程序的頂部。
截至今天,我使用了12.0庫的2.0.5版本,但最初我使用的是該dll的1.2.x版本。但是升級到最新版本什麼都沒做。我得到了同樣的結果。
我還應該注意到我查看了第三方拼寫檢查器(Component One),並且需要在字典中進行自定義。所以我希望有一種辦法可以像上週一樣使用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