返回列表 上一主題 發帖

[發問] 程式執行速度越來越慢

回復 14# bulletin
我抓台灣50,花了約56秒。

            
With wbnew.Sheets(1) 'CFSQ
               '.Rows("1:64").ClearContents
               
               '******************************
                If .QueryTables.Count > 1 Then
                    .QueryTables(1).Connection = "URL;http://dj.mybank.com.tw/z/zc/zc3/zc3_" & stockid & ".djhtm"
                Else  '沒有QueryTable時新增
                    .QueryTables.Add Connection:="URL;http://dj.mybank.com.tw/z/zc/zc3/zc3_" & stockid & ".djhtm", Destination:=.Range("$A$1")
                End If
                With .QueryTables(1)  '不再新增
                    .AdjustColumnWidth = True
                    .RefreshPeriod = 0
                    .WebSelectionType = xlSpecifiedTables
                    .WebFormatting = xlWebFormattingNone
                    .WebTables = "3"
                    .WebPreFormattedTextToColumns = True
                    .WebConsecutiveDelimitersAsOne = True
                    .Refresh BackgroundQuery:=False
                End With
                '******************************
               
           End With
         
        With wbnew.Sheets(2)
               '.Rows("1:64").ClearContents
               
               '******************************
                If .QueryTables.Count > 1 Then
                    .QueryTables(1).Connection = "URL;http://dj.mybank.com.tw/z/zc/zcq/zcq_" & stockid & ".asp.htm"
                Else  '沒有QueryTable時新增
                    .QueryTables.Add Connection:="URL;http://dj.mybank.com.tw/z/zc/zcq/zcq_" & stockid & ".asp.htm", Destination:=.Range("$A$1")
                End If
                With .QueryTables(1)  '不再新增
                    .AdjustColumnWidth = True
                    .RefreshPeriod = 0
                    .WebSelectionType = xlSpecifiedTables
                    .WebFormatting = xlWebFormattingNone
                    .WebTables = "3"
                    .WebPreFormattedTextToColumns = True
                    .WebConsecutiveDelimitersAsOne = True
                    .Refresh BackgroundQuery:=False
                End With
                '******************************
               
           End With
         
           With wbnew.Sheets(3)
               '.Rows("1:64").ClearContents
               
               '******************************
                If .QueryTables.Count > 1 Then
                    .QueryTables(1).Connection = "URL;http://dj.mybank.com.tw/z/zc/zcp/zcpa/zcpa_" & stockid & ".asp.htm"
                Else  '沒有QueryTable時新增
                    .QueryTables.Add Connection:="URL;http://dj.mybank.com.tw/z/zc/zcp/zcpa/zcpa_" & stockid & ".asp.htm", Destination:=.Range("$A$1")
                End If
                With .QueryTables(1)  '不再新增
                    .AdjustColumnWidth = True
                    .RefreshPeriod = 0
                    .WebSelectionType = xlSpecifiedTables
                    .WebFormatting = xlWebFormattingNone
                    .WebTables = "3"
                    .WebPreFormattedTextToColumns = True
                    .WebConsecutiveDelimitersAsOne = True
                    .Refresh BackgroundQuery:=False
                End With
                '******************************
               
           End With

很抱歉,我是小學生,不能下載檔案,是個小屁孩!

TOP

回復 14# bulletin
  1. Sub stest()

  2.         Dim StartTime, LastRow
  3.         Dim wbnew As Workbook
  4.       
  5.         DELETE_QueryTables
  6.       
  7.         StartTime = Timer
  8.         LastRow = Sheets("sheet1").Range("A2").End(xlDown).Row '找出最後一筆資料

  9.         Application.ScreenUpdating = False
  10.       
  11.         For i = 1 To 50
  12.             
  13.             Dim stockid
  14.             If i <= 50 Then
  15.                stockid = Range("A" & i + 10).Value
  16.             Else
  17.                stockid = Range("B" & i + 10).Value
  18.             End If
  19.             Application.DisplayAlerts = False
  20.             Application.Wait Now + TimeValue("00:00:01")
  21.             
  22.             
  23.             Set wbnew = Workbooks.Add() '新增活頁簿
  24.             'wbnew.SaveAs Filename:="C:\myStock\Test\" & stockid & ".xls"  '另存新檔
  25.             wbnew.SaveAs Filename:="C:\myStock\Test\" & stockid & "季報.xls"  '另存新檔

  26.             With wbnew.Sheets(1) 'CFSQ
  27.                '.Rows("1:64").ClearContents
  28.                
  29.                '******************************
  30.                 If .QueryTables.Count > 1 Then
  31.                     .QueryTables(1).Connection = "URL;http://dj.mybank.com.tw/z/zc/zc3/zc3_" & stockid & ".djhtm"
  32.                 Else  '沒有QueryTable時新增
  33.                     .QueryTables.Add Connection:="URL;http://dj.mybank.com.tw/z/zc/zc3/zc3_" & stockid & ".djhtm", Destination:=.Range("$A$1")
  34.                 End If
  35.                 With .QueryTables(1)  '不再新增
  36.                     .AdjustColumnWidth = True
  37.                     .RefreshPeriod = 0
  38.                     .WebSelectionType = xlSpecifiedTables
  39.                     .WebFormatting = xlWebFormattingNone
  40.                     .WebTables = "3"
  41.                     .WebPreFormattedTextToColumns = True
  42.                     .WebConsecutiveDelimitersAsOne = True
  43.                     .Refresh BackgroundQuery:=False
  44.                 End With
  45.                 '******************************
  46.                
  47.            End With
  48.          
  49.         With wbnew.Sheets(2)
  50.                '.Rows("1:64").ClearContents
  51.                
  52.                '******************************
  53.                 If .QueryTables.Count > 1 Then
  54.                     .QueryTables(1).Connection = "URL;http://dj.mybank.com.tw/z/zc/zcq/zcq_" & stockid & ".asp.htm"
  55.                 Else  '沒有QueryTable時新增
  56.                     .QueryTables.Add Connection:="URL;http://dj.mybank.com.tw/z/zc/zcq/zcq_" & stockid & ".asp.htm", Destination:=.Range("$A$1")
  57.                 End If
  58.                 With .QueryTables(1)  '不再新增
  59.                     .AdjustColumnWidth = True
  60.                     .RefreshPeriod = 0
  61.                     .WebSelectionType = xlSpecifiedTables
  62.                     .WebFormatting = xlWebFormattingNone
  63.                     .WebTables = "3"
  64.                     .WebPreFormattedTextToColumns = True
  65.                     .WebConsecutiveDelimitersAsOne = True
  66.                     .Refresh BackgroundQuery:=False
  67.                 End With
  68.                 '******************************
  69.                
  70.            End With
  71.          
  72.            With wbnew.Sheets(3)
  73.                '.Rows("1:64").ClearContents
  74.                
  75.                '******************************
  76.                 If .QueryTables.Count > 1 Then
  77.                     .QueryTables(1).Connection = "URL;http://dj.mybank.com.tw/z/zc/zcp/zcpa/zcpa_" & stockid & ".asp.htm"
  78.                 Else  '沒有QueryTable時新增
  79.                     .QueryTables.Add Connection:="URL;http://dj.mybank.com.tw/z/zc/zcp/zcpa/zcpa_" & stockid & ".asp.htm", Destination:=.Range("$A$1")
  80.                 End If
  81.                 With .QueryTables(1)  '不再新增
  82.                     .AdjustColumnWidth = True
  83.                     .RefreshPeriod = 0
  84.                     .WebSelectionType = xlSpecifiedTables
  85.                     .WebFormatting = xlWebFormattingNone
  86.                     .WebTables = "3"
  87.                     .WebPreFormattedTextToColumns = True
  88.                     .WebConsecutiveDelimitersAsOne = True
  89.                     .Refresh BackgroundQuery:=False
  90.                 End With
  91.                 '******************************
  92.                
  93.            End With
  94.          
  95.            'Windows(stockid & ".xls").Close savechanges:=True
  96.            Windows(stockid & "季報.xls").Close savechanges:=True
  97.            Application.DisplayAlerts = True

  98.         Next i
  99.       
  100.       
  101.        Application.ScreenUpdating = True
  102.        EndTime = Timer
  103.        MsgBox "本次下載共花費:" & EndTime - StartTime & "秒"
  104.          
  105.       
  106. End Sub
複製代碼
很抱歉,我是小學生,不能下載檔案,是個小屁孩!

TOP

        靜思自在 : 虛空有盡.我願無窮,發願容易行願難。
返回列表 上一主題