【问题标题】:script for autosaving Excel sheet用于自动保存 Excel 工作表的脚本
【发布时间】:2025-11-25 17:00:02
【问题描述】:

您能否给我一个线索或编码...这将在指定路径中每 1 分钟保存我打开的 Excel 工作表(即使最小化)...

不妨碍Excel的任何操作...因为通过网络查询功能我将从网络更新工作表...

<html>
<head>

var intInterval = 0 importquotes();

function importquotes()
{
filename = "E:\\Desktopp\\ami\\Daily.csv";//// ( This is the file i want to save periodically)
AmiBroker = new ActiveXObject("Broker.Application" );

 AmiBroker.Import( 0, filename, "lanka.format" );
 AmiBroker.RefreshAll();
 }
 </script>
 <button onclick="intInterval=window.setinterval('importdata()',60000);">
 start
 </button>
 <button onclick="intInterval=window.clearinterval(intInterval);">
 stop
 </button>
 </body>
   </html>

在 avobe 代码中,您可以看到我正在将 Daily.csv 数据导入到我的数据库中……我想以 1 分钟的间隔保存该 excel 表……

【问题讨论】:

  • 不。尝试自己,一旦遇到困难就回来。你没有在这里得到代码。
  • 我试了好几次...每次都失败....我不想要一个脚本在这里....一个线索 2/3 行编码可能会有所帮助....如何保存活动的 excel定期工作表....?
  • 啊,好的。好吧,我在这里帮不上忙,但希望那里有一位 Excel 大师......
  • 感谢大师们来救我....

标签: excel


【解决方案1】:

您的问题实际上是“如何将任何内容从 HTML 程序(即 JavaScript)保存到我的本地计算机”。如果您在 IE、Chrome 上运行任何 Web 浏览器,出于安全考虑,答案是没有办法的。但是,尝试 Microsoft HTA 并搜索 ado = new ActiveXObject("ADODB.Stream");和 fso = new ActiveXObject("Scripting.FileSystemObject");这些是访问本地计算机文件系统的两个可用接口。如果您的数据不包含任何 ANSI 字符,请使用 ADO,例如utf-8.

【讨论】:

    【解决方案2】:

    您希望在 VBScript 中使用如下所示的内容,但要保存而不是读取:

    Set objExcel = CreateObject("Excel.Application")
    Set objWorkbook = objExcel.Workbooks.Open("C:\Scripts\New_users.xls")
    
    intRow = 2
    
    Do Until objExcel.Cells(intRow,1).Value = ""
        Wscript.Echo "CN: " & objExcel.Cells(intRow, 1).Value
        Wscript.Echo "sAMAccountName: " & objExcel.Cells(intRow, 2).Value
        Wscript.Echo "GivenName: " & objExcel.Cells(intRow, 3).Value
        Wscript.Echo "LastName: " & objExcel.Cells(intRow, 4).Value
        intRow = intRow + 1
    Loop
    
    objExcel.Quit
    

    您可以将 1 分钟计时器放在 Excel 中的 VBA 宏中,也可以在 VBScript 中编写代码。

    【讨论】: