Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
Photo

Running an Excel Macro as a Scheduled Task


  • Please log in to reply

#1
Danimagus

Danimagus

    Member

  • Member
  • PipPip
  • 29 posts
Hello all,

I'm trying to use the Windows Scheduled Tasks utility to run an .xls and a certain macro within it. I've been able to run the .xls with no problem, but not the macro. In Access, one can do it by adding /x macroname, but no such luck with Excel, apparently.

I'd like to have the following macro, ExportAsHTMLAuto(), run through Scheduled Tasks.

===

Sub ExportAsHTMLAuto()
dTime = Now + TimeValue("00:00:05")
Application.OnTime dTime, "ExportAsHTMLAuto"

Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:= _
"T:\Dan Youngren\System\Engineering.htm" _
, FileFormat:=xlHtml, ReadOnlyRecommended:=False, CreateBackup:=False
Application.DisplayAlerts = True
Application.OnTime Now + TimeValue("00:00:05"), "Save_Exit"

End Sub

Sub Save_Exit()
Application.Quit
ThisWorkbook.Close SaveChanges:=True
End Sub

===

So, 5 seconds after Excel opens, it should save as html, then close 5 seconds later.

How do I get this to be run as a Scheduled Task?
  • 0

Advertisements


#2
dsm

dsm

    Member

  • Member
  • PipPip
  • 98 posts
danimagus,
If the Excel file opens from your scheduled event you could try utilising the events available in Excel.


eg.

Private Sub Workbook_Open()
MyMacro
End Sub

Private Sub MyMacro()
MsgBox "Hello World"
End Sub


regards
dsm
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP