简体   繁体   中英

MS Word macro to fix closest spelling error

I'm trying to create a fairly simple macro in Word 2010 using Visual Basic. All it needs to do is press Alt+F7 to select the closest spelling error, then press Enter to choose the first spelling suggestion, then press Shift+F5 to return to the previous edit point. I tried this:

SendKeys "%{F7}"
SendKeys "~"
SendKeys "+{F5}"

but the context menu that pops up after %{F7} disappears immediately so it doesn't receive the Enter key press. Instead, the selected text gets replaced with a line break. Any suggestions? I perform this sequence of key presses a lot when typing, so it would great if I could automate it.

well, I found a bit of a workaround that works:

SendKeys "{F7}{TAB}{TAB}{TAB}{TAB}{TAB}~{ESCAPE}+{F5}+{F5}"

but the dialog that pops up and the iterating through buttons is slower and clumsier than I'd like. Any better ideas would be greatly appreciated.

A little bit too late tho:

With Selection
  .MoveStartUntil Chr(9) + Chr(32), -100
  .MoveEndUntil Chr(9) + Chr(32), 100
  .Text = .Range.GetSpellingSuggestions.Item(1)
End With

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