PDA

View Full Version : Set Language Code/ Select WholeStory



sailordickie
04-19-2010, 12:53 AM
Hi Guru's

I have simplified an easrlier project to the following code. I am setting the language option to EnglishAus using the following code. It runs well and I am 99% happy with it. However as I am using the WholeStory select command, the user is always promed to check remainder of document when the spelling and grammer check runs.

Not a major but any suggested improvements to my code???

Private Sub cmdSaveExit_Click()

Application.ScreenUpdating = False

With ActiveDocument
'Unprotect
If ActiveDocument.ProtectionType = wdAllowOnlyFormFields Then
ActiveDocument.Unprotect Password:="sfu"
End If

'checks to see if user wants to update any fields

If txt_brief_num.Value = "" Then
Else
UpdateBookmark "brief_num", txt_brief_num.Value
End If

If txt_witness_name.Value = "" Then
Else
UpdateBookmark "witness_name", txt_witness_name.Value
End If

If txt_witness_title.Value = "" Then
Else
UpdateBookmark "witness_title", txt_witness_title.Value
End If

If txt_version_date.Value = "" Then
Else
UpdateBookmark "version_date", txt_version_date.Value
End If
End With
Unload Me
'Spell Check Document
Dim myRange As Range
If Options.CheckGrammarWithSpelling Then
Selection.WholeStory
Selection.LanguageID = wdEnglishAUS
End If

ActiveDocument.CheckGrammar
Application.ScreenRefresh
If ActiveDocument.SpellingErrors.Count = 0 Then
MsgBox "The spelling and grammar check is complete"
End If
Application.ScreenUpdating = True
Application.ScreenRefresh
'Reprotect
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, Password:="sfu"
With Application
.ScreenUpdating = True
.ScreenRefresh
.Dialogs(wdDialogFileSaveAs).Show
'.ActiveDocument.Saved = True
'.ActiveDocument.Close
End With
End Sub
'sub process to update multiple bookmarks
Sub UpdateBookmark(BookmarkToUpdate As String, TextToUse As String)

'Update Bookmarks
Dim BMRange As Range
Set BMRange = ActiveDocument.Bookmarks(BookmarkToUpdate).Range
BMRange.Text = TextToUse
ActiveDocument.Bookmarks.Add BookmarkToUpdate, BMRange

End Sub

fumei
04-19-2010, 12:27 PM
You have:

'Spell Check Document
Dim myRange As Range
If Options.CheckGrammarWithSpelling Then
Selection.WholeStory

You Dim a Range...but then never use it.

As for Selection.WholeStory, this sets the selection for the CURRENT whole story. There are other stories.

Therefore, use StoryRanges.
Dim aStory
For Each aStory In ActiveDocument.StoryRanges
' do your spellchecking
Next aStory
However, you may not need to check the other stories.