寻找可通过 VBA 使用的简单富文本编辑器
我希望允许我的用户在 VBA 用户窗体上的输入框中输入富文本(带有粗体、斜体和下划线,但可能仅此而已)。
我不希望用户必须安装任何内容,因此我需要利用 Office 或 Windows 已提供的功能。明显的候选者是 Windows 内置 丰富的编辑控件。
我做了一个快速测试并验证了我可以从 VBA 创建一个这种类型的窗口,但它缺少的是所有 UI 等。我真的可以帮助我如何将其变成可用的东西。
我很乐意考虑替代控件,只要保证它们不需要安装(除了作为包含其余 VBA 代码的 Excel 文件的一部分)。它需要在 Windows XP 及更高版本以及 Office 2003 及更高版本上运行。
I'd like to allow my users to enter rich text (with bold, italic & underline, but probably nothing more than that) in an entry box on a VBA userform.
I don't want the user to have to install anything, so I need this to be something that leverages what Office or Windows already provide. The obvious candidate is the Windows built-in Rich Edit control.
I did a quick test and verified that I could create a window of this type from VBA, but what it then lacks is all the UI, etc. I could really use a leg-up as to how I then turn this into something usable.
I'm happy to consider alternative controls, so long as they're guaranteed to require no installation (other than as part of the Excel file containing the rest of my VBA code). It needs to work on Windows XP and up, and Office 2003 and up.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
你可以尝试自己制作一个简单的 UI。向表单添加一个命令按钮,该按钮将在丰富的编辑控件中将选定的文本加粗。或者添加一个斜体或复制或粘贴的命令按钮。你的想象力就是你的极限。
我正在检查 Excel 2010 中的 Rich Edit 版本 1.0,我可以访问控件中的文本。
You could just try making a simple UI yourself. Add a command button to the form that will bold the selected text in the rich edit control. Or add a command button that will italicize or copy or paste. Your imagination is your limit.
I was checking Rich Edit Version 1.0 in Excel 2010, and I could access the text in the control.
对于仍在寻找这个的人。正如 Gary McGill 所说,“Microsoft InkEdit Control”是您的最佳选择。
使用下面的链接来参考它可以使用的变量:
https:// www.thevbprogrammer.com/Ch10/10-06-RichTextBox.htm
For anyone searching for this still. As Gary McGill stated, "Microsoft InkEdit Control" is your best option.
Use the link below for a reference on the variables it can use:
https://www.thevbprogrammer.com/Ch10/10-06-RichTextBox.htm
在 Excel 的 Visual Basic 编辑器中打开“工具箱”窗口后,从菜单中选择“工具”->“其他控件”。选中
MSREdit Class
旁边的框。这会将富文本控件添加到您的工具箱中。从那里您可以将其添加到用户窗体中。我在 Windows XP 上的 Office 2003 和 Windows 7 上的 Office 2010 中测试了此控件。看起来您仍然需要提供允许用户切换粗体、斜体和下划线的 UI。
它确实接受我从 Word 复制的一些富文本的粘贴(通过 Ctrl+V),但我不知道如何在将文本输入控件时切换字体格式。
With the Toolbox window open in Excel's Visual Basic editor, select Tools->Additional Controls from the menu. Check the box next to
MSREdit Class
. This will add the rich text control to your toolbox. From there you can add it to a UserForm.I tested this control in both Office 2003 on Windows XP and Office 2010 on Windows 7. It looks like you'll still need to provide the UI for allowing the user to toggle bold, italics and underline.
It does accept a paste (via
Ctrl+V
) of some rich text that I copied from Word, but I couldn't figure out how to make it switch font formating while typing text into the control.把这个放在这里只是为了排除它......
似乎“Microsoft InkEdit Control”(可从工具箱上的“附加控件”中获得)是富文本编辑控件的超集(顾名思义,它也支持墨水)。
很难判断它是否被广泛安装 - 它在我的 XP/2003 机器上,但不在我的 2K/2K 机器上。 (我看到它说它是与Vista和Win7一起安装的,但显然也有更早的版本)。
无论如何,我排除了这种可能性,因为使用该控件会在运行时生成一条消息,表明 ActiveX 控件“不安全”(可能与富文本控件本身的众所周知的问题有关)。
Putting this here just to rule it out...
It seems that the "Microsoft InkEdit Control", which is available from "Additional Controls" on the toolbox, is a superset of the Rich Text Edit control (as the name suggests, it also supports Ink).
It's hard to tell whether this is widely installed - it is on my XP/2003 machine, but not on my 2K/2K machine. (I've seen it said that it's installed with Vista and Win7, but clearly there are earlier versions too).
Anyway, I'm ruling this out because using the control results in a message at runtime to the effect that the ActiveX control is "unsafe" (presumably related to the well-known issue with the Rich Text Control itself).