very slow code in Word 2007...

R

Rob

hi,

here is a code snippet, small part of a large specific Word macro, which we
use for many, many years (>10 years), unfortunately this code runs very slow
under Word 2007...., you can test this with a random Word document...

does anybody have a solution for this? (I don't know if re-writing the
Wordbasic code to VBA will speed up the program in Word 2007, I don't know
the VBA equivalents of some Wordbasic commands...)

all suggestions are welcome!

Sub Testcase()
Dim starttime As String
Dim endtime As String
On Error GoTo ready
starttime = Time
ActiveDocument.Select
WordBasic.ScreenUpdating 0
WordBasic.EditCopy
WordBasic.CopyBookmark "\Sel", "test"
WordBasic.seltype 1
While WordBasic.CmpBookmarks("\Sel", "test") = 8 _
Or WordBasic.CmpBookmarks("\Sel", "test") = 6 _
Or WordBasic.CmpBookmarks("\Sel", "test") = 10 _
And leaveloop <> 1
WordBasic.EndOfLine
If WordBasic.CmpBookmarks("\Sel", "\EndOfDoc") = 0 Then leaveloop = 1
WordBasic.EndOfLine
WordBasic.Charright 1, 1
B = Asc(WordBasic.[GetBookmark$]("\char"))
If B <> 13 And B <> 12 And B <> 11 And B <> 14 Then
WordBasic.CharLeft
WordBasic.Underline 0
WordBasic.Bold 0
WordBasic.Insert Chr(11)
Else
WordBasic.EndOfLine
WordBasic.Charright 1, 1
WordBasic.Underline 0
WordBasic.Bold 0
WordBasic.CharLeft
WordBasic.LineDown
End If
DoEvents
Wend
ready:
endtime = Time
MsgBox "ready, starttime: " & starttime & " endtime: " & endtime
End Sub


Rob
 
R

Rob

FYI,
this (test) code without wordbasic commands and bookmarks runs just as slow
or maybe even slower....


Selection.HomeKey Unit:=wdStory
While Not Selection.Range.End = ActiveDocument.Range.End - 1
Selection.EndKey Unit:=wdLine
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
If Asc(Selection) <> 13 And Asc(Selection) <> 12 And Asc(Selection)
<> 11 And Asc(Selection) <> 14 Then
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.Font.Underline = wdUnderlineNone
Selection.Font.Bold = False
Selection.TypeText Text:=Chr(11)
Else
Selection.EndKey Unit:=wdLine
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.Font.Underline = wdUnderlineNone
Selection.Font.Bold = False
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.MoveDown Unit:=wdLine, Count:=1
End If
DoEvents
Wend
MsgBox "ready"

Rob
 
R

Rob

FYI,

the DoEvents causes the delay!!!! only in Word2007!?!

Delete the DoEvents and this will speed up this code enormously (especially
code running in a Terminal Server environment),

I hope this information will help you/someone!

Rob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top