- ©«¤l
- 96
- ¥DÃD
- 18
- ºëµØ
- 0
- ¿n¤À
- 125
- ÂI¦W
- 0
- §@·~¨t²Î
- Windows 7
- ³nÅ骩¥»
- Office 2007
- ¾\ŪÅv
- 20
- ©Ê§O
- ¨k
- µù¥U®É¶¡
- 2014-3-23
- ³Ì«áµn¿ý
- 2022-8-2
|
¦^´_ 73# GBKEE
ª©¥D¡A¤£¦n·N«ä¡A¤W¤@½g¦^ÂШ䤤¤@ÓÀɮצ³¿ù»~¡A§Ú¦A«·sªþ¤W
¥t¥~§Úªá¤F¤@¨Ç®É¶¡°µ¥X¤F¥t¤@Óª©¥»ªºµ{¦¡¡A¬O§Q¥ÎÀx¦s®æ¿é¤J¤é´Á·í§@°j°é¡A¤w´ú¸Õ¥i¥H§ì¸ê®Æ¡A¦ý¦³¨Ç¤p°ÝÃD¡G
1.¦³¨Ç»yªk§Ú¤£¤ÓÀ´«ç»ò²¤Æ¡A©Ò¥H¥i¯à¼gªº¤ñ¸û½ÆÂø¤@ÂI
2.§Q¥ÎÀx¦s®æ·í¤é´Á°j°éªº¯ÊÂI¡A´N¬O¨CӤ볣n§ó·sÀx¦s®æ¤¤ªº¤é´Á
3.§Ú¦Û¤v¼gªºµ{¦¡½X°õ¦æ¨ì¥N½X1340®ÉÁÙ¬O·|¥X¿ù¡A¤£¹L¦pªG§â²Ä¤@Ó¥N½X«·s³]¦¨1340¶}©l§ì¸ê®Æ¤S¥¿±`
4.¦]¬°ªíÀYªº¤å¦r·|«ÂЧì¨ú¡A¦ý§Ú¥u»Ýn¤@¦¸¡A©Ò¥H¥Î¤@¦C¤@¦C§R°£ªº²Â¤èªk
³oÓµ{¦¡¼gªº¤ñ¸û²ÊÁW¡A§ì¸ê®Æªº³t«×¦ü¥G¤]¤ñ¸ûºC¡A¤£¹L½T¹ê¥i¥H¹F¨ì§Ú»Ýnªºµ²ªG¡A°£¤F¹J¨ì¬Y¨Ç¥N½X·|¥d¦í»Ýn«·s³]©w¥~
¨ä¥L³£ÁÙOK¡A¦A½Ð±zÀ°¦£¬Ý¤@¤U¬O§_¦³¿ù»~ªº¦a¤è»Ýn×¥¿¡AÁÂÁ¡I
¶°«O·sªº.zip (42.48 KB)
- Option Explicit
- Sub ¶°«O§¹¦¨()
- Dim E As Range, X As Range, URL As String, xPath As String, xFile As String, rng As Range, rng1 As Range
- Dim Msg As Boolean, I As Integer, t As Date, S As String, BB As String, CC As String, rng2 As Range
- t = Time
- URL = "URL;http://www.tdcc.com.tw/smWeb/QryStock.jsp?SCA_DATE="
- BB = "&SqlMethod=StockNo&StockNo="
- CC = "&sub=%ACd%B8%DF"
- xPath = "D:\°]³ø¸ê®Æ"
- With ThisWorkbook
- With .Sheets(3)
- Set rng = .Range("A1", .Range("A1").End(xlDown))
- Set rng1 = .Range("B1", .Range("B1").End(xlDown))
- End With
- ' .Sheets(3).Activate '¨âºØ¼gªk³£¥i¥H ¤£¹L²Ä¤@ºØ¤ñ¸û²¤Æ ©Ò¥H²Ä¤GºØ¸õ¹L
- ' .Sheets(3).Range("a1").Select
- ' Range(Selection, Selection.End(xlDown)).Select
- ' Set rng = Selection
- '' Set rng = .Sheets(3).Range("A:A") '³o¸Ì³o¼Ë³]©w·|Åܦ¨µL½a°j°é
- ' .Sheets(1).Activate
- With .Sheets(1) '¬¡¶Ã¯ªº²Ä 1 ±i¤u§@ªí
- If .QueryTables.Count = 0 Then
- With .QueryTables.Add(Connection:=URL, Destination:=.Range("$A$1"))
- .Refresh BackgroundQuery:=False
- End With
- End If
-
- For Each E In rng
- With ThisWorkbook
- .Sheets(2).Cells.Clear
- ' .Activate
- .Sheets(1).Cells.Clear '¤U¸ü¸ê®Æ¸m©ó¦¹¤u§@ªí,ÅÜ´«ªÑ²¼®É:²MªÅ
- End With
- For Each X In rng1
- With .QueryTables(1)
- .Connection = URL & X & BB & E & CC
- .PreserveFormatting = True
- .BackgroundQuery = True
- .RefreshStyle = xlInsertDeleteCells
- .SaveData = True
- .AdjustColumnWidth = True
- .RefreshPeriod = 0
- .WebSelectionType = xlSpecifiedTables
- .WebFormatting = xlWebFormattingNone
- .WebTables = "6,7,8"
- On Error GoTo xlnext
- .WebPreFormattedTextToColumns = True
- .WebConsecutiveDelimitersAsOne = True
- .Refresh BackgroundQuery:=False
- End With
- Set rng2 = Sheets(1).UsedRange
- If Sheets(2).Range("a1") = "" Then
- rng2.Copy Sheets(2).Range("a" & .Rows.Count).End(xlUp)
- Else
- rng2.Copy Sheets(2).Range("a" & .Rows.Count).End(xlUp).Offset(2, 0)
- End If
- Next X
- xlnext:
- Sheets(2).Range("2:2,22:22,43:43,64:64,85:85,106:106,127:127,148:148,169:169,190:190,211:211,232:232,253:253").Delete
- xFile = xPath & "\" & E & "\SHD.txt"
- MkDir_Sub xFile '10#ªºµ{¦¡ 'C¼Ñ¤Uªº©u·l¯qªí¸ê®Æ§¨¤£»Ý¥ý«Ø¥ß
- Maketxt xFile, Sheets(2).UsedRange
- ' S = " " & Sheets(1).QueryTables(1).ResultRange(1)
- ' If Val(S) < 0 Then S = " ¬dµL"
- I = I + 1
- Application.StatusBar = Application.Text(Time - t, ["MM¤ÀSS¬í"]) & " " & E & "¶×¤J" & I & "Ó¤å¦rÀÉ"
- Msg = False
- Next E
- End With
- End With
- MsgBox "¦@¶×¤J ¤å¦rÀÉ" & I & " ¶O®É " & Application.Text(Time - t, ["MM¤ÀSS¬í"])
- End Sub
- Sub MkDir_Sub(S As String)
- Dim AR, I As Integer, xPath As String
- If Dir(S) = "" Then
- AR = Split(S, "\")
- xPath = AR(0)
- For I = 1 To UBound(AR) - 1
- xPath = xPath & "\" & AR(I)
- If Dir(xPath, vbDirectory) = "" Then MkDir xPath
- Next
- End If
- End Sub
- Sub Maketxt(xF As String, Q As Range) '±N¶×¤J¸ê®Æ¦s¤J«ü©wªºtxt
- Dim fs As Object, E As Range, C As Variant
- Set fs = CreateObject("Scripting.FileSystemObject")
- Set fs = fs.CreateTextFile(xF, True) '³Ð¨£¤@ÓÀÉ®×,¦pÀɮצs¦b¥iÂл\±¼
- For Each E In Q.Rows
- C = Application.Transpose(Application.Transpose(E.Value))
- C = Join(C, vbTab)
- fs.WriteLine C
- Next
- fs.Close
- End Sub
½Æ»s¥N½X |
|