开发者

How can I get Excel to programmatically write to CSV?

开发者 https://www.devze.com 2023-02-26 21:17 出处:网络
At the moment my spreadsheet reads financial data.I would like to programmatically dump this 开发者_如何学Cto CSV every second.How can I do this in VBA?Something like this should work:

At the moment my spreadsheet reads financial data. I would like to programmatically dump this 开发者_如何学Cto CSV every second. How can I do this in VBA?


Something like this should work:

Sub SetTimeout()
    Application.OnTime Now + TimeValue("00:00:30"), "SaveAsCSV"
End Sub

Sub SaveAsCSV()
    Calculate
    ActiveWorkbook.SaveAs Filename:="book1.csv", FileFormat:=xlCSV, CreateBackup:=False
    Call SetTimeout
End Sub

Just call SetTimeout() whenever you want to start saving and it will do so every 30 seconds from then on (hence the Now + TimeValue("00:00:30") part)

0

精彩评论

暂无评论...
验证码 换一张
取 消