[問題] VBA擷取網路上xls檔的資料出錯

看板Office作者 (官人)時間9年前 (2016/08/16 09:54), 編輯推噓0(003)
留言3則, 2人參與, 最新討論串1/1
軟體:excel 版本:2010 我想試著抓msci台灣指數的權重表直接匯入excel https://www.msci.com/eqb/custom_indexes/tw_performance.xls 過去使用的程式碼如下,抓網頁跟csv都可以用,但這次抓xls不行 會在.Refresh BackgroundQuery:=False 這裡顯示"不正確的web查詢" 請問高手們該如何解決? Sub test() Set DataSheet = ActiveSheet Range("A1").CurrentRegion.ClearContents qurl = "網址" QueryQuote: With ActiveSheet.QueryTables.Add(Connection:="URL;" & qurl, Destination:=DataSheet.Range("A1")) .AdjustColumnWidth = False .BackgroundQuery = True .TablesOnlyFromHTML = False .Refresh BackgroundQuery:=False .SaveData = True End With End Sub -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 123.51.219.89 ※ 文章網址: https://www.ptt.cc/bbs/Office/M.1471312491.A.C9F.html

08/16 10:06, , 1F
用workbooks.add 接網址,試試
08/16 10:06, 1F

08/16 10:09, , 2F
如要用唯讀的話 workbooks.open 接網址
08/16 10:09, 2F

08/16 10:15, , 3F
已解決!原來這樣就行了,非常感謝
08/16 10:15, 3F
文章代碼(AID): #1Nid9hoV (Office)
文章代碼(AID): #1Nid9hoV (Office)