运行循环时自动保存文件

时间:2015-12-13 17:36:13

标签: excel vba excel-vba autosave

我有一长串本地网页,这些网页将由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

对此有何想法?

1 个答案:

答案 0 :(得分: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