简体   繁体   中英

VB Spell Check Code issue

I have managed to assemble the following code for spell checking a locked document but just cant quit get it to work. I would like it to look at only unlocked cells but still use the 'CommandBars("Tools").Controls("Spelling...").Execute' function. Any ideas would be great. TIA

Sub SelectUnlockedCells_Spellcheck()

ActiveSheet.Unprotect Password:=""

    Dim WorkRange As Range

    Dim FoundCells As Range

    Dim Cell As Range

    Set WorkRange = ActiveSheet.UsedRange

    For Each Cell In WorkRange

        If Cell.Locked = False Then

            If FoundCells Is Nothing Then

                Set FoundCells = Cell

            Else

                Set FoundCells = Union(FoundCells, Cell)

            End If

        End If

    Next Cell

    If FoundCells Is Nothing Then
        MsgBox "All cells are locked."

    Else

        FoundCells.CheckSpelling CommandBars("Tools").Controls("Spelling...").Execute

    End If

ActiveSheet.Protect Password:=""

End Sub

You are using this code

FoundCells.CheckSpelling CommandBars("Tools").Controls("Spelling...").Execute

But the VBA help doesn't show any such parameters. Try using just this:

FoundCells.CheckSpelling

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM