2015-12-13 23 views
0

我有一個本地網頁的長列表,這些列表將由Excel 2013中的宏解析。我想知道是否有任何方法可以每隔5分鐘左右自動保存文件循環瀏覽這些文件(> 9000本地.HTM文件)。運行循環時自動保存文件

下面是一些代碼:

Sub ImportFromWebPages() 

'declare here some global variables 

For startnumber = 1 to 9126 

    'parse the .HTM files and extract the needed data 
    'while running this loop (which will take some days to finish) 
    'Excel should save the file every 5 or 10 minutes. 

Next startnumber 
End Sub 

對這個有什麼想法?

+0

你應該顯示你的完整代碼 - '運行這個循環時(這將需要幾天的時間完成)'。這是極端的! – brettdj

回答

4

在一定數量的文件之後保存會比較容易,比如說5。請原諒我的僞代碼:

Sub ImportFromWebPages() 

    'declare here some global variables 

    For startnumber = 1 to 9126 

     'parse the .HTM files and extract the needed data 
     'while running this loop (which will take some days to finish) 
     'Excel should save the file every 5 or 10 minutes. 

     If startnumber Mod 5 = 0 Then 

      ActiveWorkbook.Save 

     End If 

    Next startnumber 
End Sub 

請參閱更多關於ModActiveWorkbook.Save以下鏈接。

+1

或者查看= Now()函數將時間合併到循環中 –

+1

謝謝。這對我的情況也很好。 – user3185735