I use the code below to search for a bookmark then replace the default value with a new string. The problem is it is very slow. I have to replace about 50 bookmarks for a form and so it takes > say 10 seconds.
I have turned off screen updating before calling this routine, but you can still see the Word document scroll bars moving as the program updates each book mark value. It seems as though the program is still somehow updating the document display - which would explain why it is so slow.
Any ideas on how to speed up this process?
'replace book mark value with new value if it exists
Public Sub ReplaceBookMarkValue(sBookMarkName As String, sBookMarkValue As String)
'Replace book mark value with value from control
If Application.ActiveDocument.Bookmarks.Exists(sBookMarkName) Then
On Error Resume Next
Selection.GoTo What:=wdGoToBookmark, Name:=sBookMarkName
Selection.FormFields(1).TextInput.EditType Type:=wdRegularText, Default:=sBookMarkValue
On Error GoTo 0
End If
End Sub
I have turned off screen updating before calling this routine, but you can still see the Word document scroll bars moving as the program updates each book mark value. It seems as though the program is still somehow updating the document display - which would explain why it is so slow.
Any ideas on how to speed up this process?
'replace book mark value with new value if it exists
Public Sub ReplaceBookMarkValue(sBookMarkName As String, sBookMarkValue As String)
'Replace book mark value with value from control
If Application.ActiveDocument.Bookmarks.Exists(sBookMarkName) Then
On Error Resume Next
Selection.GoTo What:=wdGoToBookmark, Name:=sBookMarkName
Selection.FormFields(1).TextInput.EditType Type:=wdRegularText, Default:=sBookMarkValue
On Error GoTo 0
End If
End Sub