[問題] 讀取多個檔案,並import至同一表單

看板Office作者 (不要鯽魚我)時間12年前 (2014/05/28 22:10), 編輯推噓0(002)
留言2則, 1人參與, 最新討論串1/1
軟體:Excel 2013 版本:2013 大家好, 想請教前輩高手關於VBA編寫的問題 現在在 資料夾中,有3個擷取網路頁面的htm的檔案 1.htm 2.htm 3.htm 在htm網頁裡,當中的第8個表格資料是我要的 我希望將他們讀取進同一個表單,並且如下面這樣 |------------------------------------------------ |1.htm 's table | | |---------------|-------------------------------| |2.htm 's table |←接著 1.url's table 下面一行 | |---------------|-------------------------------| |3.htm 's table |←接著 2.url's table 下面一行 | |-----------------------------------------------| 但是我現在得到的卻... -------------------------------------------------- |3.htm 's table | 2.htm 's table | 1.htm 's table| |---------------|----------------|---------------| | 3的資料 | 2的資料 | 1的資料 | -------------------------------------------------- 請問...我該怎麼修改呢!!! 謝謝!! 程式碼如下: --- Sub LoadPipeDelimitedFiles() Dim idx As Integer Dim fpath As String Dim fname As String idx = 0 fpath = "C:\Users\xxxx\Desktop\aaaaa\" fname = Dir(fpath & "*.htm") While (Len(fname) > 0) idx = idx + 1 Sheets("Sheet1").Select With ActiveSheet.QueryTables.Add(Connection:="URL;" _ & fpath & fname, Destination:=Range("A1")) .Name = "a" & idx .FieldNames = True .RowNumbers = False .FillAdjacentFormulas = False .PreserveFormatting = True .RefreshOnFileOpen = False .RefreshStyle = xlInsertDeleteCells .SavePassword = False .SaveData = True .AdjustColumnWidth = True .RefreshPeriod = 0 .WebSelectionType = xlSpecifiedTables .WebFormatting = xlWebFormattingNone .WebTables = "8" .WebPreFormattedTextToColumns = True .WebConsecutiveDelimitersAsOne = True .WebSingleBlockTextImport = False .WebDisableDateRecognition = False .WebDisableRedirections = False .Refresh BackgroundQuery:=False fname = Dir End With Wend End Sub -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.112.4.235 ※ 文章網址: http://www.ptt.cc/bbs/Office/M.1401286255.A.46D.html

05/28 22:47, , 1F
Destination:=Range("A1") 這樣應該要改為可判斷最後一格
05/28 22:47, 1F

05/28 22:49, , 2F
有資料的儲存格(end(xldown)再用offset下移一格
05/28 22:49, 2F
文章代碼(AID): #1JXUvlHj (Office)
文章代碼(AID): #1JXUvlHj (Office)