使用形状作为按钮接受从形状文本框接受用户输入的问题

发布于 2025-01-31 11:07:02 字数 822 浏览 4 评论 0原文

希望有人可以帮助我解决这个Excel/VBA问题。

最近,我开始用形状控件替换活跃的X控件,希望更少的问题和更好的性能,但是当试图通过单击形状按钮从形状文本框中接受用户输入时,我偶然发现了一个奇怪的问题。

我已经设置了一个简单的工作表来证明问题,它只是具有以下形状。

  1. 用于输入的形状文本框,我锁定了形状并解锁了文本。
  2. 带有文字的按钮名称的形状按钮,我锁定了形状并锁定了文本。

单击按钮并运行宏时,它将文本从文本框复制到单元格A1

注意:我已经保护了表格,除了单元格A1之外,

我希望用户将某些文本输入文本框,然后立即将其输入单击按钮接受输入,该按钮将运行一个宏,该宏将对文本有所作为。

我发现仅在单击按钮的外部区域时才发现宏才能起作用,当用户在嵌入在按钮上的文本附近并占用该按钮的大部分中心区域时,它将无法正常工作。同样,当我将鼠标悬停在按钮上时,鼠标指针会更改为不存在文本的移动指针,对于带有文本的区域,它会更改为文本指针。

如果我在单击按钮之前首先单击输入文本框中,然后按预期工作,鼠标指针显示预期的链接指针。

我的测试示例

以下是为按钮宏分配的代码;

Sub Test()

    Range("A1") = Sheet1.Shapes("TextBox 1").TextFrame.Characters.Text

End Sub

任何帮助将不胜感激

Hope somebody can help me with this Excel/VBA issue.

I have recently started replacing my active X controls with shape controls hoping for less issues and better performance, however I've stumbled across a strange issue when trying to accept user input from a shape textbox by clicking on a shape button.

I've setup a simple worksheet to demonstrate the problem, it simply has the following shapes;

  1. Shape textbox used for input, I have locked the shape and unlocked the text.
  2. Shape button with text for the button name, I have locked the shaped and locked the text.

When the button is clicked and the macro runs it copies the text from the textbox to cell A1

Note: I have protected the sheet except for cell A1

I want the user to input some text into the textbox then immediately click on the button to accept the input, the button will run a macro which will do something with the text.

I've discovered the macro only works when the outside area of the button is clicked, it won't work when the user clicks near the text which is embedded on the button and takes up most of the center area of that button. Also when I hover over the button the mouse pointer changes to a move pointer where text isn't present and for the area with the text it changes to a text pointer.

If I click out of the input text box first into a worksheet cell before clicking the button then it works as expected and the mouse pointer shows the expected link pointer.

My test example

Below is the code assigned for the button macro;

Sub Test()

    Range("A1") = Sheet1.Shapes("TextBox 1").TextFrame.Characters.Text

End Sub

Any help would be greatly appreciated

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文