- 帖子
- 5923
- 主題
- 13
- 精華
- 1
- 積分
- 5986
- 點名
- 0
- 作業系統
- win10
- 軟體版本
- Office 2010
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台灣基隆
- 註冊時間
- 2010-5-1
- 最後登錄
- 2022-1-23
        
|
19#
發表於 2014-1-4 08:56
| 只看該作者
本帖最後由 GBKEE 於 2014-1-4 08:57 編輯
回復 18# blue2263 - Option Explicit
- Sub Ex()
- Dim Rng(1 To 2) As Range
- On Error Resume Next '執行程式碼如有錯誤繼續執行下一個程式碼: 股票Web有錯誤時
- With Sheets("巨集工作表")
- Set Rng(1) = .Range("B2")
- .Activate
- End With
- 'Sheets("匯總").UsedRange.Offset(1).Clear '用此程式碼" 如需清除舊有資料
- Do While Rng(1) <> ""
- Rng(1).Activate
- With Sheets("原始表")
- .Range("B2") = Rng(1)
- .Range("E7").QueryTable.Refresh BackgroundQuery:=False
- Set Rng(2) = .Range("A10:K29") '你要的原始資料
- End With
- If Err = 0 Then
- Application.StatusBar = Rng(1) & " 匯入中"
- With Sheets("匯總").Range("A1").End(xlDown).Offset(1)
- .Range("A1:K20").Value = Sheets("匯總").Range("A2:K21").Value
- Rng(1).Parent.Hyperlinks.Add Anchor:=Rng(1).Offset(, 2), Address:="", SubAddress:=.Address(, , , 1), TextToDisplay:=.Parent.Name & "!" & .Address(0, 0)
- '重新設定超連結
- End With
-
- '************'用此程式碼:配合需清除舊有資料 ******************************
- 'With Sheets("匯總").Range("A" & Sheets("匯總").Rows.Count).End(xlUp).Offset(1)
- ' .Resize(Rng(2).Rows.Count, Rng(2).Columns.Count) = Rng(2).Value
- ' Rng(1).Parent.Hyperlinks.Add Anchor:=Rng(1).Offset(, 2), Address:="", SubAddress:=.Address(, , , 1), TextToDisplay:=.Parent.Name & "!" & .Address(0, 0)
- 'End With
- '********************************************
-
- Else
- With Rng(1).Offset(, 2)
- .Hyperlinks.Delete '股票Web錯誤:刪除超連結
- .Value = ""
- End With
- Err.Clear
- End If
- Set Rng(1) = Rng(1).Offset(1)
- Loop
- Application.StatusBar = " 工作 完成 !!"
- End Sub
複製代碼 |
|