Excel VBA。从其他应用程序检索文本
我试图从另一个应用程序中检索文本,只返回3个空格。 (这一点受到了强烈的启发)Excel VBA。从其他应用程序检索文本,excel,vba,Excel,Vba,我试图从另一个应用程序中检索文本,只返回3个空格。 (这一点受到了强烈的启发) Ret=FindWindow(vbNullString,“koelskerN-R1Q2 b4449(端口27910)”) 如果Ret为0,则 ChildRet=FindWindowEx(Ret,ByVal 0&,“编辑”,vbNullString) strBuff=String(GetWindowTextLength(ChildRet)+1,Chr$(0)) GetWindowText ChildRet、strBuf
Ret=FindWindow(vbNullString,“koelskerN-R1Q2 b4449(端口27910)”)
如果Ret为0,则
ChildRet=FindWindowEx(Ret,ByVal 0&,“编辑”,vbNullString)
strBuff=String(GetWindowTextLength(ChildRet)+1,Chr$(0))
GetWindowText ChildRet、strBuff、Len(strBuff)
ButCap=strBuff
debug.print strBuff'刚刚返回3。(空格)
如果结束
Ret返回值=8062086
ChildRet返回值=9309970
我以前没有真正尝试过使用FindWindow,所以我希望能得到一些关于如何从类中提取文本和编辑类的指导。我发现,应用程序有一个日志文件1,它将所有内容提取到一个.txt文件。这个问题解决了。使用@SiddharthRout示例,您可以单击此编辑框,然后只需将
SendKeys
复制到剪贴板中的文本,然后从内存中读取。
Ret = FindWindow(vbNullString, "koelskerN - R1Q2 b4449 (port 27910)")
If Ret <> 0 Then
ChildRet = FindWindowEx(Ret, ByVal 0&, "Edit", vbNullString)
strBuff = String(GetWindowTextLength(ChildRet) + 1, Chr$(0))
GetWindowText ChildRet, strBuff, Len(strBuff)
ButCap = strBuff
debug.print strBuff 'Is just returning 3. blank spaces)
End If