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