OnTime Function Call

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am writing a VB.NET plugin for Excel. I want to call the
ApplicationObject.Ontime function to call another function after a specified
time.
AppObj.OnTime Now + TimeSerial(0, 0, 5), "MyCustom SubName"

I tried putting the calling and called function in the same class but it
throws an error. "Exception from HRESULT: 0x800A03EC."

I also tried putting the called function in a Global Module but no success..
still the same exception.

This thing works in a Macro( wherein i specify ThisworkBooK.<CALLED FUNCTION
Name>)

Does the Ontime Function work in an application or just that it works in a
Macro?
If it does, what is the right way to call it?

thanks for your suggestions.

-Satin
 
Satin,

This

Now + TimeSerial(0, 0, 5)

is what's causing your problems. Try something like this:

Dim xlapp As New Excel.Application
Dim xlwb As Excel.Workbook
xlwb = xlapp.Workbooks.Open("D:\sample.xls")
xlwb.Application.OnTime(Now.AddSeconds(5), "SubName")


where SubName is a public Sub inside a module in the sample.xls file.
 
If xlwb is new, it won't have any macros to execute. How about either
creating from a template, or putting the macro in Personal.xls?

Carl.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top