3

我正在维护一个用 VBA 为 Excel 2002 (XP)/2003 编写的老式应用程序,并试图将其国际化。

为此,我动态读取翻译后的字符串,并通过更新其 .Caption 属性来更新我的用户窗体上的各种控件。

这适用于所有控件,但不适用于表单本身 - 当我更改表单的 .Caption 属性时,标题栏会继续显示“硬编码”值,而新值则显示在它的正下方,在表单本身的“画布”的顶部。

是否可以在显示后更改 UserForm 的标题栏文本,或者我必须在显示之前更改表单的 .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 = "###!!@@NOTFOUND@@!!###"
    ' ...
    ' 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。

4

1 回答 1

1

frmFoo实际上与 base 不是同一类型UserForm,而是在 VBA 的怪异 OO 实现中从内部“继承”它,因此您不能可靠地将其用作参数类型,而是使用 Object 会起作用;

Sub TranslateDialog(pForm As Object, pFormName As String)
于 2010-06-04T10:21:46.283 回答