简体   繁体   English

Excel VBA-单击“用户窗体”按钮后,将焦点返回到工作表

[英]Excel VBA - return focus to worksheet after UserForm Button click

I have a UserForm with a button that alters the font of the selected cell on the active, visible worksheet. 我有一个带按钮的UserForm,它可以更改活动的可见工作表上所选单元格的字体。

When I click the button, I want the underlying VBA to execute, and then for focus to move back to the selected cell. 当我单击按钮时,我希望基础VBA执行,然后使焦点移回到所选单元格。

Right now, focus remains with the UserForm, so it requires an extra mouse click on the target cell to resume editing the cell content. 现在,焦点仍然放在UserForm上,因此需要在目标单元格上额外单击鼠标以恢复编辑单元格内容。

I've tried adding ActiveSheet.Activate and ActiveCell.Activate at the end of the button VBA routine; 我尝试在按钮VBA例程的末尾添加ActiveSheet.Activate和ActiveCell.Activate; no joy. 不开心

How might I get the original ActiveCell to have focus after the UserForm button click? 单击用户窗体按钮后,如何才能使原始ActiveCell具有焦点?

A couple of things to think about. 需要考虑的几件事。

a) is your form modal or modeless a)您的表格是模态还是无模

b) on the button click do you want to hide the form or keep it visible? b)在按钮上单击要隐藏表格还是使其保持可见状态?

c) am assuming you want to edit the selected cell, if so you need it to go into edit mode with c)假设您要编辑所选单元格,如果需要,则需要使用以下命令进入编辑模式

SendKeys "{F2}"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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