views:

192

answers:

1

I'm maintaining an old-ish application written in VBA for Excel 2002 (XP)/2003, and am trying to internationalise it.

To do this, I read in the translated strings dynamically and update the various controls on my userform by updating their .Caption property.

This works as expected for all controls but not for the form itself -- when I change the form's .Caption property, then the title bar keeps displaying the "hard-coded" value, and the new value is instead displayed just below it, at the top of the "canvas" of the form itself.

Is it possible to change the title bar text of a UserForm after it has been shown, or do I have to change the .Caption property of the form before it is shown in order for it to be reflected in the title bar rather than in the canvas/client area?

My code looks something like this:

' 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

As I said, the assignment to pForm.Caption does have an effect - but it doesn't write to the title bar of the window, but rather directly beneath it. I'm running Excel 2003 on Windows XP SP 3.

A: 

Your frmFoo is not actually the same type as the base UserForm, rather it's internally "descended" from it in VBA's wierd OO implementation so you can't use that reliably as a parameter type, using Object instead will work;

Sub TranslateDialog(pForm As Object, pFormName As String)
Alex K.
Excellent - thanks for your help! That did indeed work.
Philip Newton