1
我正在维护一个使用VBA for Excel 2002(XP)/ 2003编写的旧应用程序,并试图对其进行国际化。如何更改VBA中Userform的标题栏文本?
为此,我动态读取翻译后的字符串,并通过更新其.Caption属性来更新我的用户窗体上的各种控件。
这对预期的所有控件都能正常工作,但对于表单本身不起作用 - 当我更改表单的.Caption属性时,标题栏会一直显示“硬编码”值,而新值则仅显示在它下面,在窗体本身的“画布”的顶部。
是否有可能在用户窗体显示后更改标题栏文本,还是必须在显示窗体的.Caption属性之前更改该窗体的.Caption属性,以便将其反映到标题栏中而不是在画布/客户区?
我的代码看起来是这样的:
' in frmFoo
Private Sub UserForm_Activate()
' ...
TranslateDialog Me, "frmFoo"
' ...
End Sub
' in a VBA module
Sub TranslateDialog(pForm As UserForm, pFormName As String)
Dim new Caption As String
Const notFound As String = "###[email protected]@[email protected]@!!###"
' ...
' GetMessage() returns the translated message for a given key, or the
' default value (second parameter) if no translation is available.
' The translation key for the form caption is the form name itself.
newCaption = GetMessage(pFormName, notFound)
If newCaption <> notFound Then pForm.Caption = newCaption
' ...
End Sub
正如我所说的,分配给pForm.Caption
确实有效果 - 但它不会写入到窗口的标题栏,而是直接在其下方。我在Windows XP SP 3上运行Excel 2003.
非常好 - 感谢您的帮助!那确实有效。 – 2010-06-16 16:02:32