Dear: everyone! I want to retrieve data as the data string length in the Formula Bar (the formula bar, rather from its Edit Box) I have used the following
1. Declare Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Const WM_GETTEXTLENGTH = & HE Public Const C_EXCEL_WINDOW = "XLMAIN" Public Const C_EXCEL_EDITBOX = "EXCEL <" Take the handle of the Formula Bar
Public Function hWndEditbox () As Long
Dim hWndMain As Long
HWndMain = FindWindow(C_EXCEL_WINDOW, Application.Caption)
HWndEditbox = FindWindowEx (hWndMain, ByVal 0 &, C_EXCEL_EDITBOX, vbNullString) End Function
3. Get the length of the data string in the formula With 03 ways Way
1 MsgBox SendMessage (hWndEditbox, WM_GETTEXTLENGTH, ByVal 0 &, ByVal 0 &)
2 mystr = String (255, Chr $ (0))
MsgBox GetWindowText (hWndEditbox, mystr, Len (mystr))
MsgBox GetWindowTextLength(hWndEditbox)
Yet the result is always 0 (although there are still data in the Formula Bar) So please ask people to answer help why and how to fix
1. Declare Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Const WM_GETTEXTLENGTH = & HE Public Const C_EXCEL_WINDOW = "XLMAIN" Public Const C_EXCEL_EDITBOX = "EXCEL <" Take the handle of the Formula Bar
Public Function hWndEditbox () As Long
Dim hWndMain As Long
HWndMain = FindWindow(C_EXCEL_WINDOW, Application.Caption)
HWndEditbox = FindWindowEx (hWndMain, ByVal 0 &, C_EXCEL_EDITBOX, vbNullString) End Function
3. Get the length of the data string in the formula With 03 ways Way
1 MsgBox SendMessage (hWndEditbox, WM_GETTEXTLENGTH, ByVal 0 &, ByVal 0 &)
2 mystr = String (255, Chr $ (0))
MsgBox GetWindowText (hWndEditbox, mystr, Len (mystr))
MsgBox GetWindowTextLength(hWndEditbox)
Yet the result is always 0 (although there are still data in the Formula Bar) So please ask people to answer help why and how to fix
Last edited: