< návrat zpět
MS Excel
Téma: Načtení textu z programu a vložení do excelu
Zaslal/a DusanU 21.4.2017 20:17
Ahoj,
chtěl bych se zeptat, jestli je možné získat text z textboxu jiného programu a vložit ho do excelu.
Jako přílohu přikládám jednoduchý program, ve kterém jsou tři textboxy.
Děkuji
Příloha: 36141_program.zip (15kB, staženo 29x)
cmuch1(21.4.2017 20:29)#036142 Antivir hlasi že je to VIR
citovat
DusanU(14.5.2017 13:29)#036334 Přikládám řešení:
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public 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
Public Declare Function GetWindowTextLength Lib "user32.dll" Alias _
"GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Public Declare Function GetWindowText Lib "user32.dll" Alias _
"GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As _
String, ByVal cch As Long) As Long
Dim sInput As String
Dim hwnd As Long, lhWndChild As Long
Dim textlen As Long '<~~ Length of text of title
Dim titleText As String '<~~ Text of the title
Dim slength As Long '<~~ Length of the returned string
Sub Sample()
'~~> Form Caption
sInput = "Program"
'~~> Get Handle of the Form
hwnd = FindWindow(vbNullString, sInput)
'~~> loop through the Child Windows
Do
lhWndChild = FindWindowEx(hwnd, lhWndChild, vbNullString, vbNullString)
textlen = GetWindowTextLength(lhWndChild)
titleText = Space(textlen + 1)
'~~> Get the text of the window
slength = GetWindowText(lhWndChild, titleText, textlen + 1)
'~~> Extract information from the buffer
titleText = Left(titleText, slength)
Debug.Print "Value of Child Window is "; titleText
Loop While lhWndChild
End Sub
citovat