View Single Post
 
Old 07-02-2023, 07:00 PM
coffent coffent is offline Windows 10 Office 2019
Advanced Beginner
 
Join Date: Dec 2019
Posts: 40
coffent is on a distinguished road
Default SendKeys doesn't work reliably

I have a simple visual basic program that adds a blank comment to a cell and then should open the comment for editing. It adds the blank comment correctly, but it opens the comment only about half the time (more or less randomly). I think the problem is that sometimes - but not always! - the Active Cell loses focus so it doesn't receive the SendKeys output. Is there a way to insure that the Active Cell stays active?

Code:
Sub AddBlankComment()
    ActiveCell.AddComment ("")  ' Adds blank comment
    SendKeys "+{F2}", True      ' Excel shortcut (shift-F2) to open comment for editing
                                ' (True causes program to wait for action to complete.)
End Sub
Reply With Quote