如何加快Word 2007自动化 [英] how to speed up word 2007 automation
本文介绍了如何加快Word 2007自动化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Imports Word = Microsoft.Office.Interop.Word
Imports System.Runtime.InteropServices
Dim oWord As Word.Application
Dim oDoc As Word.Document
oWord = CreateObject("Word.Application")
oDoc = oWord.Documents.Open("Test.doc")
oWord.Visible = False
oDoc.SpellingChecked = False
oWord.ScreenUpdating = False
oWord.CheckLanguage = False
oDoc.GrammarChecked = False
oWord.AutoCorrect.CorrectCapsLock = False
oWord.AutoCorrect.CorrectDays = False
oWord.AutoCorrect.CorrectHangulAndAlphabet = False
oWord.AutoCorrect.CorrectInitialCaps = False
oWord.AutoCorrect.CorrectKeyboardSetting = False
oWord.AutoCorrect.CorrectSentenceCaps = False
在我的代码中,我正在阅读段落,并将每个字符串替换为其他字符串.
因此还剩下什么,以便提高代码执行速度.
In my code I am reading paragraph and replace each string with other string.
so what else remaining so that I increase my code execution speed.
sReplace = "AbCD"
ofind = oWord.Selection.Find
For Each oPara1 In oWord.ActiveDocument.Paragraphs
myRange = oPara1.Range
Dim str1 As String = oPara1.Range.Text
Dim str2 As String = Midstr(str1)'remove space form string
If str2 <> Nothing Then
bResult = IsUnicode(str2)
If bResult = True Then
Else
With ofind
.ClearFormatting()
.Text = str2
.Replacement.ClearFormatting()
.Replacement.Text = sReplace
.MatchCase = True
.MatchWholeWord = True
.Wrap = Word.WdFindWrap.wdFindContinue
.Execute(Replace:=Word.WdReplace.wdReplaceAll)
End With
End If
End If
oWord.Selection.MoveDown(Unit:=Word.WdUnits.wdParagraph, Count:=1)
Next
代码包装在"pre"标签中[/编辑]
Code is wrapped in "pre" tag[/Edited]
推荐答案
记住:自动化本质上相对较慢.
—SA
Keep in mind: automation is inherently relatively slow.
—SA
这篇关于如何加快Word 2007自动化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文