如何用VBA把EXCEL表中的内容输出到其他程序的文本框中?
我现在的难题是找不到指定文本框的句柄,以及如何通过句柄对文本框的内容进行操作。如果有多个文本框怎么可以判定句柄?现在的难题是找不到指定文本框的句柄...
我现在的难题是找不到指定文本框的句柄,以及如何通过句柄对文本框的内容进行操作。
如果有多个文本框怎么可以判定句柄?现在的难题是找不到指定文本框的句柄 展开
如果有多个文本框怎么可以判定句柄?现在的难题是找不到指定文本框的句柄 展开
1个回答
展开全部
'新建或打开一个abc.txt 文本文件,下面代码稍加注释,自己理解一下,其它软件的文本框获取句柄的方法一样,这里给你写操作,你也可以进行读取操作,所以修改当然是不成问题的
Option Explicit
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 SendMessage Lib "user32 " Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Const WM_SETTEXT = &HC
Sub test()
Dim s As String, myhwnd As Long
myhwnd = FindWindow(vbNullString, "abc.txt - 记事本")
myhwnd = FindWindowEx(myhwnd, 0&, "Edit", vbNullString) '控件名用spy++查看,这里是Edit,特定的软件控件名都是固定的
If myhwnd = 0 Then
MsgBox "!!"
Exit Sub
End If
s = [a1]
SendMessage myhwnd, WM_SETTEXT, 0, ByVal s
End Sub
'-------------------------------
'都给你写了测试例了,首先会用api函数,其次会用spy++,其它的就是体力活了。要找到程序的hwn然后找到hwn下面的文本框,,,。
Option Explicit
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 SendMessage Lib "user32 " Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Const WM_SETTEXT = &HC
Sub test()
Dim s As String, myhwnd As Long
myhwnd = FindWindow(vbNullString, "abc.txt - 记事本")
myhwnd = FindWindowEx(myhwnd, 0&, "Edit", vbNullString) '控件名用spy++查看,这里是Edit,特定的软件控件名都是固定的
If myhwnd = 0 Then
MsgBox "!!"
Exit Sub
End If
s = [a1]
SendMessage myhwnd, WM_SETTEXT, 0, ByVal s
End Sub
'-------------------------------
'都给你写了测试例了,首先会用api函数,其次会用spy++,其它的就是体力活了。要找到程序的hwn然后找到hwn下面的文本框,,,。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询