Home > OS >  Find Immediate Windows localized name in Excel-VBA
Find Immediate Windows localized name in Excel-VBA

Time:07-12

Is there a way in VBA-Excel to find how is named the Immediate window in a localized version of Microsoft Office Excel, not English ?
For example, I use an Italian version of Excel, and here Immediate window is called "Immediata",
other, for example Dutch here, called it "Direct" and so on...
I'm trying to modify a function finded in the page linked above, but I wish to release a version able to work in any localized version of MsO Excel.
Thanks in advance for the answer.

CodePudding user response:

'                                              
'  Function to find the name of the localized  
'  version of the Immediate windows.           
'                                              
Public Function LocalizedImmediateWin() As String

' String pass to the MsgBox.
Dim strMsg As String
' This Integer'll contain the total number of the VBE Windows.
Dim intNumWin As Integer
' This Integer is used as counter in the For...Next loop.
Dim intLoop As Integer

    ' Count the number of all the windows (show or hidden) in the VBE.
    intNumWin = Application.VBE.Windows.Count
    ' Loop for all the windows find, starting from 1.
    For intLoop = 1 To intNumWin
        ' If the Type of the Windows we're examine is an Immediate Windows then
        If Application.VBE.Windows.Item(intLoop).Type = vbext_wt_Immediate Then
            ' Build the MsgBox.
            strMsg = MsgBox("In this localized version of " & Chr(13) & Chr(10) & "Microsoft Office Excel, " & Chr(13) & Chr(10) & "Immediate windows is called:" & Chr(13) & Chr(10) & Chr(13) & Chr(10) & Application.VBE.Windows.Item(intLoop).Caption & "", vbCritical, "Localized Immediate")
            ' Pass the value as result of the Function.
            LocalizedImmediateWin = Application.VBE.Windows.Item(intLoop).Caption
            Exit For
        End If
    ' Next windows to examine.
    Next intLoop
    
' End of the function.
End Function

' Simple way to try.
Sub Try()
    MsgBox LocalizedImmediateWin
End Sub

CodePudding user response:

The name of the Immediate Window is available in the Window object with the type vbext_wt_Immediate. This type is only available with the correct imports, but all it says is vbext_wt_Immediate = 5. Instead of creating a reference to this, it can be declared and used like this:

Const VBEXT_WT_IMMEDIATE = 5

Function ImmediateLabel() As String        
    For Each win In Application.VBE.Windows
        If win.Type = VBEXT_WT_IMMEDIATE Then
            ImmediateLabel = win.Caption
        End If
    Next
End Function

Sub Test()
    Debug.Print ImmediateLabel
End Sub
  • Related