查找和替换Word 2007 Automation中的错误 [英] Error in Find and Replace Word 2007 Automation
本文介绍了查找和替换Word 2007 Automation中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在vb.net中尝试自动执行查找和替换"的Word文档时,出现以下错误:
exception SEHException
这是我的代码:-
When trying to automate a word document for Find And Replace in vb.net I get the following error:
exception SEHException
This is my code:-
Imports Word = Microsoft.Office.Interop.Word
Dim sFind As String
Dim sReplace As String
sFind = "findme"
sReplace = "findyou"
Dim oWord As Word.Application
Dim oDoc As Word.Document
Try
oWord = CreateObject("Word.Application")
oDoc = oWord.Documents.Open("E:\test1.docx")
oDoc.Activate()
Dim myStoryRange As Microsoft.Office.Interop.Word.Range
For Each myStoryRange In oDoc.StoryRanges
With myStoryRange.Find
.Text = sFind
.Replacement.Text = sReplace
.Wrap = Microsoft.Office.Interop.Word.WdFindWrap.wdFindContinue
.Execute(Replace:=Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll)
End With
Next myStoryRange
oDoc.SaveAs("E:\test2.docx")
oDoc.Close()
oDoc = Nothing
oWord.Application.Quit()
oWord = Nothing
Catch ex As Exception
MessageBox.Show("Error accessing Word document.")
End Try
End Sub
推荐答案
尝试这种方式
Word自动化 [ http://social.msdn.microsoft.com/Forums/zh/vbide/thread/1558f560-8ae6-413a-bbc4-aa8d5d912aac [ http://msdn.microsoft.com/en-us/library/system. runtime.interopservices.sehexception.aspx [
Try this way
Word Automation[^]
http://social.msdn.microsoft.com/Forums/en/vbide/thread/1558f560-8ae6-413a-bbc4-aa8d5d912aac[^]
Check the details ofSEHException
if that helps.
http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.sehexception.aspx[^]
SEHException通常是指不是由.Net而是由本机组件抛出的异常.您应该在您的异常处理程序catch块中放置一个断点,并检查ExternalException.ErrorCode
属性并查看其含义.还要检查您的堆栈跟踪,因为您可能能够确定哪个组件引发了错误.
希望对您有帮助
SEHException generally refers to an exception that has not been thrown by .Net but by a native component. You should put a breakpoint inside your exception handler catch block and check theExternalException.ErrorCode
property and see what it says. Check your stacktrace also, as you might be able to determine which component is throwing the error.
Hope this helps
这篇关于查找和替换Word 2007 Automation中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文