寻找一个可以从 VBA 中使用的简单的富文本编辑器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8256115/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Looking for a simple rich-text editor usable from VBA
提问by Gary McGill
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.
我想允许我的用户在 VBA 用户表单的输入框中输入富文本(带有粗体、斜体和下划线,但可能仅此而已)。
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.
我不希望用户必须安装任何东西,所以我需要它能够利用 Office 或 Windows 已经提供的东西。显而易见的候选者是 Windows 内置的Rich Edit 控件。
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.
我做了一个快速测试并验证我可以从 VBA 创建一个这种类型的窗口,但是它缺少的是所有的 UI 等。我真的可以使用一个关于如何将它变成可用的东西的方法。
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.
我很乐意考虑替代控件,只要它们保证不需要安装(除了作为包含其余 VBA 代码的 Excel 文件的一部分)。它需要在 Windows XP 及更高版本以及 Office 2003 及更高版本上运行。
回答by Bobort
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.
您可以尝试自己制作一个简单的 UI。向窗体添加一个命令按钮,该按钮将在 Rich Edit 控件中加粗所选文本。或添加将斜体或复制或粘贴的命令按钮。你的想象力是你的极限。
I was checking Rich Edit Version 1.0 in Excel 2010, and I could access the text in the control.
我在 Excel 2010 中检查 Rich Edit Version 1.0,我可以访问控件中的文本。
回答by Gary McGill
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).
工具箱上的“附加控件”中提供的“Microsoft InkEdit 控件”似乎是富文本编辑控件的超集(顾名思义,它也支持 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).
很难说这是否广泛安装——它在我的 XP/2003 机器上,但不在我的 2K/2K 机器上。(我看到它说它安装了 Vista 和 Win7,但显然也有早期版本)。
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).
无论如何,我排除了这一点,因为使用该控件会在运行时产生一条消息,表明 ActiveX 控件是“不安全的”(大概与 Rich Text 控件本身的众所周知的问题有关)。
回答by CoderDennis
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.
在 Excel 的 Visual Basic 编辑器中打开 Toolbox 窗口后,从菜单中选择 Tools->Additional Controls。选中旁边的框MSREdit Class
。这会将富文本控件添加到您的工具箱中。从那里您可以将其添加到用户窗体。
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.
我在 Windows XP 上的 Office 2003 和 Windows 7 上的 Office 2010 中测试了此控件。看起来您仍然需要提供 UI 以允许用户切换粗体、斜体和下划线。
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.
它确实接受Ctrl+V
我从 Word 复制的一些富文本的粘贴(通过),但我无法弄清楚如何在将文本输入控件时切换字体格式。