OFF95: Macro to Spell Check a Binder

ID: Q152578


The information in this article applies to:
  • Microsoft Office for Windows 95, versions 7.0, 7.0a, 7.0b


SUMMARY

By default, spell checking is not provided across all sections of a binder. If you want to check the spelling of each section in your binder, you must first activate each section and then check the spelling while the document is activated.

This article provides a sample Microsoft Excel Visual Basic for Applications macro for checking the spelling of all the Microsoft Word and Microsoft Excel sections in a binder file. Note, since Microsoft PowerPoint does not have a Spell checking method in its Object model, the macro does not contain any code to check the spelling of PowerPoint presentations.


MORE INFORMATION

Microsoft provides examples of Visual Basic for Applications procedures for illustration only, without warranty either expressed or implied, including, but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. The Visual Basic procedures in this article are provided 'as is' and Microsoft does not guarantee that they can be used in all situations. While Microsoft support professionals can help explain the functionality of a particular macro, they will not modify these examples to provide added functionality, nor will they help you construct macros to meet your specific needs. If you have limited programming experience, you may want to consult one of the Microsoft Solution Providers. Solution Providers offer a wide range of fee-based services, including creating custom macros. For more information about Microsoft Solution Providers, call Microsoft Customer Information Service at (800) 426-9400.

Before entering the sample macro code below, do the following:

  1. Open a new binder document.


  2. Add a new Microsoft Word 6.0 Document section to the binder.


  3. Enter the misspelled word "dogg", without quotes, in your Word document.


  4. Add a new Microsoft Excel 5.0 Worksheet section to the binder.


  5. Enter the misspelled word "catt", without quotes, in cell A1.


  6. With the Microsoft Excel section active, click View Outside on the Section menu.

    Step 6 is necessary to add a module sheet to the Microsoft Excel section and to be able to enter macro code into the module sheet.


  7. Insert a module sheet in the workbook, and enter the following code into the module sheet:
    
        Sub Check_Spelling_In_Binder()
            Dim BindObj As Object
            Dim WrdBasic As Object
            Dim BindSct
        
            On Error Resume Next
            'Create a reference to the Binder
            Set BindObj = ActiveWorkbook.Container.Parent
        
            active_section = BindObj.ActiveSection.Name
        
            'Loop through all of the Binder sections.
            For Each BindSct In BindObj.sections
                BindSct.Activate
        
                '"If" structure to determine type of section
                If BindSct.Type Like "Excel.Sheet.*" Then
                    BindSct.Object.Cells.CheckSpelling _
                        customdictionary:="custom.dic", _
                        ignoreuppercase:=False, alwayssuggest:=True
        
                ElseIf BindSct.Type Like "Word.Document.*" Then
        
                    ' If Word.Basic object not created, create it
                    If WrdBasic Is Nothing Then Set WrdBasic = _
                    CreateObject("word.basic")
                    WrdBasic.toolsspelling
        
                ElseIf BindSct.Type Like "Excel.Chart.*" Then
                    BindSct.Object.CheckSpelling _
                        customdictionary:="custom.dic", _
                        ignoreuppercase:=False, alwayssuggest:=True
                Else
                    'This would be a PowerPoint section.
                    'No Spell check method in Powerpoint object model.
        
                End If
        
            Next BindSct
        
            'reactivate the section from which this macro was launched
            BindObj.sections(active_section).Activate
        
            Set BindObj = Nothing
            Set WrdBasic = Nothing
        End Sub
       


  8. On the File menu click Close to return to the Binder.


  9. On the Tools menu click Macro and in the Macro dialog box double- click the macro "Check_Spelling_In_Binder" to run the macro.


The macro should run and the spelling checker for both Word and Microsoft Excel should come up while the respective binder section is active and tell you that it found a misspelled word. When the macro has finished, the section that was active when you ran the macro will be activated.


REFERENCES

"Microsoft Office for Windows 95 Resource Kit," Chapter 12, "Support and Troubleshooting"

Keywords :
Version : 7.00 7.00a 7.00b
Platform : WINDOWS
Issue type :


Last Reviewed: June 3, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.