0

I am looking to Save an Open Excel File programmatically without any user interaction. This could be a Script running as Scheduled task, or running as a windows service. Can you please guide me in the direction which I can then work on?

Regards, Saurabh

sdeshpande
  • 311
  • 1
  • 2
  • 4

1 Answers1

0

You can indeed do this with just excel and it's macros.

In essence you simply just need to save the book every x seconds. So in order to do something every x seconds, starting from when the workbook is open, you do this: (Put that code in for when the workbook opens)

alertTime = Now + TimeValue("00:02:00")
Application.OnTime alertTime, "EventMacro"

Then just have a macro in the workbook called "EventMacro" that will repeat it.

Public Sub EventMacro()
    '... Execute your actions here'
    alertTime = Now + TimeValue("00:02:00")
    Application.OnTime alertTime, "EventMacro"
End Sub

For the '... Execute your actions here': You can use the line: ActiveWorkbook.Save to save your current excel sheet.

This should accomplish what you're looking for.

Previous answer this is based on here, and documentation for saving here.

Community
  • 1
  • 1
Rivasa
  • 6,510
  • 3
  • 35
  • 64