如何使用excel VBA将文本发送到外部应用程序中的“编辑框”

时间:2019-05-29 15:52:59

标签: excel-vba

我已经编写了用于将文本发送到其他Web基础应用程序(.appref-ms)的代码,我的代码正在打开该应用程序,但是我的代码中有些错误,因为无法从病房的变量“ main_window1”中找到应用程序窗口。(请参阅从WINSPECTOR捕获图片

Public Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" ( _
     ByVal lpClassName As String, _
     ByVal lpWindowName As String) As Long

Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
     ByVal hwnd As Long, _
     ByVal lpOperation As String, _
     ByVal lpFile As String, _
     ByVal lpParameters As String, _
     ByVal lpDirectory As String, _
     ByVal nShowCmd As Long) As Long

Public Declare Function SendMessageByString Lib "user32.dll" Alias "SendMessageA" ( _
     ByVal hwnd As Long, _
     ByVal wMsg As Long, _
     ByVal wParam As Long, _
     ByRef lParam As Any) As Long


Public Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" ( _
     ByVal hwnd As Long, _
     ByVal wMsg As Long, _
     ByVal wParam As Long, _
     ByRef lParam As Any) As Long

Public Const SW_SHOWMAXIMIZED As Long = 3

Public Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" ( _
ByVal hWndParent As Long, _
ByVal hWndChildAfter As Long, _
ByVal lpszClass As String, _
ByVal lpszWindow As String) As Long

Public Const WM_SETTEXT As Long = &HC
Public Const BM_CLICK As Long = &HF5&

Public Declare Function GetWindow Lib "user32.dll" ( _
     ByVal hwnd As Long, _
     ByVal wCmd As Long) As Long

Sub run_application()
Dim str As String
str = "C:\Users\Guest\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned\StartMenu\Excellon 5.appref-ms"
hwnd = FindWindow(VBA.Constants.vbNullString, "Excellon")
start_doc = ShellExecute(hwnd, "open", str, "", "", SW_SHOWMAXIMIZED)
If start_doc = 2 Then Exit Sub
If start_doc = 3 Then Exit Sub

Do
DoEvents
hwindow2 = FindWindow(vbNullString, "Excellon")
Loop Until hwindow2 > 0

main_window1 = FindWindowEx(hwindow2, 0&, "layoutControl1", vbNullString)
main_window2 = FindWindowEx(main_window1, 0&, "0011037C", vbNullString)
main_window3 = FindWindowEx(main_window3, 0&, "EDIT", vbNullString)

Call SendMessageByString(main_window3, WM_SETTEXT, 0, "123")
DoEvents
[enter image description here][1]
End Sub\[enter image description here\]\[1\]

enter image description here

0 个答案:

没有答案