ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

[µo°Ý] ¦p¦ó¦bVBA¤¤¨Ï¥ÎSendMessage©ÎPostMessage¨Ó¹ï"ÀɮפU¸ü"¹ï¸Ü²°¶i¦æ¾Þ§@

[µo°Ý] ¦p¦ó¦bVBA¤¤¨Ï¥ÎSendMessage©ÎPostMessage¨Ó¹ï"ÀɮפU¸ü"¹ï¸Ü²°¶i¦æ¾Þ§@

¥»©«³Ì«á¥Ñ white5168 ©ó 2012-6-23 20:19 ½s¿è

½Ð°Ý¦U¦ì¤j¤j,­n¦p¦ó¦bVBAªºÀô¹Ò¤¤¨Ï¥ÎSendMessage©ÎPostMessage¨Ó¹ï"ÀɮפU¸ü"¹ï¸Ü²°¶i¦æ¾Þ§@?
¦pºô§}  http://www.twse.com.tw/ch/trading/fund/BFI82U/BFI82U_print.php?begin_date=20120611&end_date=&report_type=day&language=ch&save=csv

¥H¤U¬O§Ú¨Ï¥Î¹Lªº¤èªk,¦ý¨ÌµLªk¦¨¥\
  1. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
  2. 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
  3. Private Declare Function PostMessage& Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any)
  4. Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
  5. 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
  6. Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)

  7. Private Const WM_LBUTTONDOWN = &H201
  8. Private Const WM_LBUTTONUP = &H202
  9. Private Const BM_CLICK = &HF5
  10. Private Const MOUSEEVENTF_LEFTDOWN = &H2
  11. Private Const MOUSEEVENTF_LEFTUP = &H4

  12. Sub test()
  13.     Dim IE As Object
  14.     Dim hpwnd As Long, hcwnd As Long
  15.     Dim iRet As Long
  16.    
  17.     Set IE = CreateObject("InternetExplorer.Application") '³]©wInternetExplorerª«¥ó

  18.     strLink = "http://www.twse.com.tw/ch/trading/fund/BFI82U/BFI82U_print.php?begin_date=20120611&end_date=&report_type=day&language=ch&save=csv" 'ÀɮפU¸üºô§}
  19.    
  20.    
  21.    With IE
  22.         .Visible = True  '¶}±ÒIE
  23.         .Navigate strLink   '³sµ²ºô§}
  24.     End With
  25.    
  26.    
  27.     Do
  28.         hpwnd = FindWindow("#32770", "ÀɮפU¸ü") '§ì¨ú¹ï¸Ü²°ªºhandle
  29.         DoEvents
  30.     Loop While hpwnd = 0
  31.    
  32.     Do
  33.         hcwnd = FindWindowEx(hpwnd, 0, "Button", "Àx¦s(&S)") '§ì¨ú¹ï¸Ü²°«ö¶sªºhandle
  34.         DoEvents
  35.     Loop While hcwnd = 0

  36.     iRet = SetForegroundWindow(hcwnd) '³]©wµJÂI

  37.    '¦b¥H¤U¤­ºØ¤èªk¸g¬Ò¥Ñwindowsµo°e°T®§¼Ò¥é·Æ¹««öÁä,,¨ÌµMµLªk½Ð°Ý¦U¦ì¬O§_¦³¨ä¥L¤èªk¥i¥H°µ¨ìwindowsµo°e°T®§¼Ò¥é·Æ¹««öÁä
  38.     '¤èªk¤@
  39.     iRet = SendMessage(hcwnd, BM_CLICK, 0, 0)               '³z¹Lwindowsµo°e°T®§¼Ò¥é·Æ¹««öÁä

  40.     '¤èªk¤G
  41.     'iRet = SendMessage(hcwnd, WM_LBUTTONDOWN, 0, 0)        '·Æ¹«¥ªÁä«ö¤U
  42.     'iRet = SendMessage(hcwnd, WM_LBUTTONUP, 0, 0)          '·Æ¹«¥ªÁäÄÀ©ñ

  43.     '¤èªk¤T
  44.     'PostMessage hcwnd, WM_LBUTTONDOWN, 0&, CLng(&H90009)   '·Æ¹«¥ªÁä«ö¤U
  45.     'PostMessage hcwnd, WM_LBUTTONUP, 0&, CLng(&H90009)     '·Æ¹«¥ªÁäÄÀ©ñ
  46.     'PostMessage hcwnd, WM_LBUTTONDOWN, 0&, CLng(&H90009)   '·Æ¹«¥ªÁä«ö¤U
  47.     'PostMessage hcwnd, WM_LBUTTONUP, 0&, CLng(&H90009)     '·Æ¹«¥ªÁäÄÀ©ñ

  48.     '¤èªk¥|
  49.     'mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0           '³z¹L·Æ¹«¨Æ¥ó, ·Æ¹«¥ªÁä«ö¤U
  50.     'mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0             '³z¹L·Æ¹«¨Æ¥ó, ·Æ¹«¥ªÁäÄÀ©ñ
  51.    
  52.     '¤èªk¤­
  53.     'SendKeys "%s", True   '³z¹L«ö¤UAlt + s Àx¦sÀÉ®×

  54.     Set IE = Nothing    'ÄÀ©ñ¸ê·½
  55. End Sub
½Æ»s¥N½X

§Ú¦³»Ý­n¤@©w­nª½±µ¥h¾Þ§@¹ï¸Ü®Ø,§Ú·íµMª¾¹D¦³¨ä¥Lªº¤èªk¥i¥H§ì¨ú,¥i¬O´N¤@©w»Ý­nª½±µ¾Þ§@¹ï¸Ü®Ø

TOP

¾Ç®üµL²P_¤£®¢¤U°Ý

TOP

¨S¦³¤j¤j·Q¨ì¤èªk?

TOP

        ÀR«ä¦Û¦b : ªY½à§O¤H´N¬O²øÄY¦Û¤v¡C
ªð¦^¦Cªí ¤W¤@¥DÃD