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

[µo°Ý] ¥N½XÀ³¸Ó¦p¦ó¼¶¼g¤~¯à©¿µø ¦]¬d¸ß¤£¨ì¦Ó²£¥Íªººô­¶°T®§©O¡H

  1. Option Explicit

  2. #If Win64 = 1 Then
  3. Private Declare PtrSafe Function GetWindow Lib "user32" (ByVal HWND As Long, ByVal wCmd As Long) As Long
  4. Private Declare PtrSafe Function SetForegroundWindow Lib "user32" (ByVal HWND As Long) As Long
  5. #Else
  6. Private Declare Function GetWindow Lib "user32" (ByVal HWND As Long, ByVal wCmd As Long) As Long
  7. Private Declare Function SetForegroundWindow Lib "user32" (ByVal HWND As Long) As Long
  8. #End If

  9. Private Const GW_HWNDNEXT = 2
  10. Private Const GW_CHILD = 5

  11. Sub ex()
  12.     Dim lHwndChild&
  13.    
  14.     With CreateObject("InternetExplorer.Application")
  15.         .Visible = True
  16.         .Navigate "https://dl.dropboxusercontent.com/u/40393708/test1.htm"
  17.         Do While .Busy Or .ReadyState <> 4
  18.             DoEvents
  19.             If 3 = .ReadyState Then
  20.                 lHwndChild = GetWindow(.HWND, GW_CHILD)
  21.                 Do While lHwndChild
  22.                     SetForegroundWindow .HWND 'HWND is the HWND of the myIEWindow
  23.                     Application.SendKeys "~", True
  24.                     lHwndChild = GetWindow(lHwndChild, GW_HWNDNEXT)
  25.                 Loop
  26.             End If
  27.         Loop
  28.     End With
  29.    
  30. End Sub
½Æ»s¥N½X
¦^´_ 8# joey0415

TOP

¦^´_ 10# joey0415
¤j·§´N¬O½T»{IE¬O§_¦³¥ô¦ó¤lµøµ¡Åã¥Ü(ex:°T®§µøµ¡)¡A¦³´N±NIE¤Á´«¦¨³Ì¤W¼hÅã¥Ü«á¦A°e¥XENTERÁä±N°T®§µøµ¡Ãö³¬¡C
³]©w­È½Ð°Ñ¦Ò¤U¦Cºô§}:
https://msdn.microsoft.com/zh-tw/ms633515
¥t¥~§Ú¼gªº¹L©ó²¤Æ¡A³]·Q¦pªGµo¥Í¤lµøµ¡µLªk¥ÎENTERÁäÃö³¬ªº±¡ªp¡A§A³Ì¦n¥[¤W¿ù»~³B²z¾÷¨î(ex:°e¥XENTERÁä´X¦¸µL®Ä«á´N¤£¦A°õ¦æ§ïÅã¥Ü¿ù»~°T®§)¡A¤£µM¦³¥i¯à·|¶i¤J¦º°j°é...

TOP

¦^´_ 12# joey0415
§Ú¥Î§A¤W­±¶Kªºµ{¦¡½X¤ÎGBKEEª©¥D±Ðªº¤èªk³£¨S¦³¥X²{°ÝÃD(¥Î Win7 + IE11 + Office2013),©Ò¥H§Ú¤]¤£¾å±o¥X¤F¤°»ò°ÝÃD...
³o°ÝÃD¦pªGµu®É¶¡¤ºµLªk¸Ñ¨M§A¤S«æ»Ý³o¨Ç¸ê®Æ,¤U¦Cºô§}¥i¥H§ì¨ì³Ì·s¤@´Áªº¸ê®Æ(csvÀÉ):
http://data.gov.tw/node/11452

TOP

¦^´_ 14# joey0415
¥t¤@ºØ¤è¦¡,¸Õ¸Õ¬Ý...
  1. Option Explicit

  2. #If Win64 Then
  3. Private Declare PtrSafe Function GetWindow Lib "USER32" (ByVal hWnd As LongPtr, ByVal wCmd As LongPtr) As LongPtr
  4. Private Declare PtrSafe Function SetForegroundWindow Lib "USER32" (ByVal hWnd As Long) As Long
  5. Private Declare PtrSafe Function FindWindow Lib "USER32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr
  6. Private Declare PtrSafe Function FindWindowEx Lib "USER32" Alias "FindWindowExA" (ByVal hWnd1 As LongPtr, ByVal hWnd2 As LongPtr, ByVal lpsz1 As String, ByVal lpsz2 As String) As LongPtr
  7. Private Declare PtrSafe Function SendMessage Lib "USER32" Alias "SendMessageA" (ByVal hWnd As LongPtr, ByVal wMsg As Long, ByVal wParam As LongPtr, lParam As Any) As LongPtr
  8. #Else
  9. Private Declare Function GetWindow Lib "user32" (ByVal HWND As Long, ByVal wCmd As Long) As Long
  10. Private Declare Function SetForegroundWindow Lib "user32" (ByVal HWND As Long) As Long
  11. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
  12. Private Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
  13. Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hWnd As Long, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
  14. #End If

  15. Private Const WM_CLOSE = &H10
  16. Private Const GW_HWNDNEXT = 2
  17. Private Const GW_CHILD = 5
  18. Private Const BM_CLICK = &HF5

  19. Sub ÂIÀ»()
  20.     Cells.Clear
  21.     Dim hWndChild, hWndPopup, x, Retries As Integer: Retries = 10
  22.    
  23.     With CreateObject("InternetExplorer.Application")
  24.         .Visible = True
  25.         .Navigate "http://www.tdcc.com.tw/smWeb/QryStock.jsp"
  26.         
  27.         Do While .Busy Or .ReadyState <> 4  'µ¥­Ôºô­¶¤U¸ü§¹²¦
  28.             DoEvents
  29.         Loop
  30.         Set x = .document.all.tags("option") '¬d¤U©Ô¿ï³æ
  31.         x(7).Selected = True '¿ï¨ú¸Ó¤l¶µ¥Ø
  32.         
  33.         .document.getElementsByName("StockNo")(0).Value = "6456"
  34.         .document.getElementsByName("sub")(0).Click
  35.         
  36.         Do While (.Busy Or .ReadyState <> 4) And 0 < Retries
  37.         
  38.             hWndChild = GetWindow(.hWnd, GW_CHILD)
  39.         
  40.             If 0 <> hWndChild Then
  41.                 Do While hWndChild
  42.                     hWndPopup = FindWindow("#32770", "ºô­¶°T®§") '#32770 The class for a dialog box
  43.                     If 0 <> hWndPopup Then
  44.                         SendMessage FindWindowEx(hWndPopup, 0, "Button", "½T©w"), BM_CLICK, 0, 0
  45.                     Else
  46.                         Exit Do
  47.                     End If
  48.                     'SetForegroundWindow .hWnd 'HWND is the HWND of the myIEWindow
  49.                     'Application.SendKeys "~", True
  50.                     hWndChild = GetWindow(hWndChild, GW_HWNDNEXT)
  51.                 Loop
  52.             
  53.             End If
  54.             Application.Wait Now + #12:00:01 AM#
  55.             DoEvents
  56.             Retries = Retries - 1
  57.         Loop
  58.         If 0 = Retries Then
  59.             AppActivate Application.Caption
  60.             MsgBox "µLªkÃö³¬°T®§µøµ¡!", vbCritical
  61.             Exit Sub
  62.         End If
  63.         '-------------------¥H¤U¬°¥¢µJ³B¡AµLªkÂIÀ»
  64.         Stop
  65.         .document.getElementsByName("StockNo")(0).Value = "1101"
  66.         .document.getElementsByName("sub")(0).Click
  67.             
  68.         Do While .Busy Or .ReadyState <> 4  'µ¥­Ôºô­¶¤U¸ü§¹²¦
  69.            DoEvents
  70.         Loop
  71.         
  72.         Stop
  73.         .Quit
  74.     End With

  75. End Sub
½Æ»s¥N½X

TOP

        ÀR«ä¦Û¦b : µoµÊ®ð¬Oµu¼ÈªºµoºÆ¡C
ªð¦^¦Cªí ¤W¤@¥DÃD