Spellcheck Macro for Visual Studio | CodeGuru

Spellcheck Macro for Visual Studio

Environment: Visual C++ 6 Have you ever wanted to quickly check to see if one word is spelled right while coding with Visual Studio? Of course you have! This macro let’s you put the cursor on the word (or highlight the part you want to check) and tells you if it’s correct or wrong. If […]

Written By
CodeGuru Staff
CodeGuru Staff
Feb 18, 2001
1 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

Environment: Visual C++ 6

Have you ever wanted to quickly check to see if one word is spelled right while coding
with Visual Studio? Of course you have! This macro let’s you put the cursor on the word (or
highlight the part you want to check) and tells you if it’s correct or wrong. If wrong, it
will give you a list of suggestions of the correct spelling. COM is great!

You can click on any word, or highlight the word/exact part you wish to spellcheck.

NOTE: You must have Microsoft Word 97 or 2000 installed for this macro to work.

For those that need it, installation instructions:

In Visual Studio, click tools->macro, enter the name “Spellcheck” and click Edit. Cut and past the
macro from below in over the default one.

To choose the hotkey that runs it, click the Options button, then keystrokes. You can
assign any key combination you wish.

Sub Spellcheck()
Dim txtCredit
Set MSWord = CreateObject(Word.Application)
Dim colSuggestions
Dim suggestion
Dim txtFinalto hold the final results 
txtCredit =Visual Studio Spell Checker by Seth A. Robinson”
‘Converted from an example fromProgramming Visual Basic”
‘MSWord.visible = trueuncomment this to see whats really 
‘happpening behind the scenes
 ‘ Add a document if there arent any (needed to get 
 ‘ suggestions).
 If MSWord.Documents.Count = 0 Then MSWord.Documents.Add
 If ActiveDocument.Selection.Text = “” Then
  ‘They didnt choose anything, so lets grab the word theyset the cursor on
  ActiveDocument.Selection.WordRight
  ActiveDocument.Selection.WordLeft dsExtend
 End If
 Dim txt_temp
 txt_temp = ActiveDocument.Selection.Text
 If MSWord.CheckSpelling(txt_temp) Then
  ‘ The word is correct.
  MsgBox “It appears “””&txt_temp&””” is spelled correctly.,_
         vbInformation,txtCredit
 Else
  ‘Word is wrong, lets get some suggestions of right ones.
  Set colSuggestions = MSWord.GetSpellingSuggestions(txt_temp)
  txtFinal =It appears “””&txt_temp&””” is spelled wrong.+_
             ” Here are some possible replacements:&vbLf&vbLf
  If colSuggestions.Count = 0 Then
   MsgBox txtFinal&(no suggestions),vbCritical, txtCredit
  Else
   For Each suggestion In colSuggestions
    txtFinal = txtFinal&suggestion.name&vbLf
   Next
   ‘show suggestions to user
   MsgBox txtFinal,vbCritical, txtCredit
  End If
 End If
 ‘Kill document, dont leave it floating in memory
 MSWord.ActiveWindow.Close wdDoNotSaveChanges
End Sub
CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.