返回列表 上一主題 發帖

vba匯入券商進出表

vba匯入券商進出表

thanks.rar (12.69 KB) http://yamstock.megatime.com.tw/asp/stockinfo/ps_top.asp?m=all&stockid=3474&name1=D2&index1=6
這是yan券商進出表
想用vba匯入excel 指定工作簿及存儲格
如2888新光金匯入"sheet2", "A1"
2409友達匯入"sheet2", "A60"
以下程式碼是我網路搜尋並依我的需要自行俢改
但是還是無法執行
請前輩幫忙看看
到底那裡錯誤   謝謝
   

Sub GetTransInfo()
Worksheets("sheet2").Activate
Call 券商進出("2888", "sheet2", "A1")
Call 券商進出("2409", "sheet2", "A60")
End Sub
     Sub 券商進出(stock As String, tsheet As String, tcell As String)
Call券商進出("all&stockid", "8,10,11", stockinfo, tsheet, tcell)
End Sub
Sub券商進出(all&stockid, tbl As String, stock As String, tsheet As String, tcell As String)
     With Worksheets(tsheet).QueryTables.Add(Connection:="URL;http://yamstock.megatime.com.tw/asp/stockinfo/ps_top.asp?m=all&stockid=" & _
     stockNo &  "&name1=D2&index1=6, _
        .Destination:=Worksheets(tsheet).Range(tcell))
        .Name = all & "_" & stock
         .FieldNames = True
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = False
        .RefreshStyle = xlOverwriteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .WebSelectionType = xlSpecifiedTables
        .WebFormatting = xlWebFormattingNone
        .WebTables = tbl
        .WebPreFormattedTextToColumns = True
        .WebConsecutiveDelimitersAsOne = True
        .WebSingleBlockTextImport = False
        .WebDisableDateRecognition = False
        .WebDisableRedirections = False
        .Refresh BackgroundQuery:=False
    End With

    End Sub

你可以試試一句一句試試了解一下意思
  1. Sub GetTransInfo()
  2. Worksheets("sheet2").Activate
  3. Call 券商進出("2885", "sheet2", "A1")
  4. 'Call 券商進出("2409", "sheet2", "A60")
  5. End Sub
  6. Sub 券商進出(stock As String, tsheet As String, tcell As String)
  7.     '"all&stockid",
  8.     Call 券商進出2("8,10,11", stock, tsheet, tcell)
  9. End Sub

  10. '(all&stockid,
  11. Sub 券商進出2(tbl As String, stock As String, tsheet As String, tcell As String)
  12.      With Worksheets(tsheet).QueryTables.Add(Connection:="URL;http://yamstock.megatime.com.tw/asp/stockinfo/ps_top.asp?m=all&stockid=" & _
  13.         stock & "&name1=D2&index1=6", _
  14.         Destination:=Worksheets(tsheet).Range(tcell))
  15.         .Name = all & "_" & stock
  16.          .FieldNames = True
  17.         .FieldNames = True
  18.         .RowNumbers = False
  19.         .FillAdjacentFormulas = False
  20.         .PreserveFormatting = True
  21.         .RefreshOnFileOpen = False
  22.         .BackgroundQuery = False
  23.         .RefreshStyle = xlOverwriteCells
  24.         .SavePassword = False
  25.         .SaveData = True
  26.         .AdjustColumnWidth = True
  27.         .RefreshPeriod = 0
  28.         .WebSelectionType = xlSpecifiedTables
  29.         .WebFormatting = xlWebFormattingNone
  30.         .WebTables = tbl
  31.         .WebPreFormattedTextToColumns = True
  32.         .WebConsecutiveDelimitersAsOne = True
  33.         .WebSingleBlockTextImport = False
  34.         .WebDisableDateRecognition = False
  35.         .WebDisableRedirections = False
  36.         .Refresh BackgroundQuery:=False
  37.     End With

  38.     End Sub
複製代碼
懂得發問,答案就會在其中

今日の一秒は  明日にない
http://kimbalko-chi.blogspot.com
http://kimbalko.blogspot.com

TOP

感謝版主kimbal
正確解決無誤
版主回覆
你可以試試一句一句試試了解一下意思
是呀新手就是一個字一個字的學習

TOP

恩   版主用心了  謝謝

TOP

第8行的"8,10,11"
第16行的.Name = all & "_" & stock
第31行的.WebTables = tbl
是什麼意思?
80 字節以內
不支持自定義 Discuz! 代碼

TOP

        靜思自在 : 【停滯不前,終無所得】人都迷於尋找奇蹟,因而停滯不前;縱使時間再多、路再長,也了無用處,終無所得。
返回列表 上一主題