2010-06-04 106 views
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.

回答

1

您的frmFoo實際上與基準UserForm不是同一類型,而是在VBA的奇怪OO實現中內部「下降」,因此您無法可靠地使用它作爲參數類型,使用Object而不是工作;

Sub TranslateDialog(pForm As Object, pFormName As String) 
+0

非常好 - 感謝您的幫助!那確實有效。 – 2010-06-16 16:02:32

相關問題