You cannot pass an object as an argument with the method John (Green)
demonstrated. How to use a variable is something Peter has already shown
you.
You can always use a global variable to pass an object to a OnTime procedure
-- provided you can guarantee that that object variable will remain
untouched, and in your case I believe that will indeed be true.
So, in a standard module:
public aWB as workbook
sub CreateNewWorksheet ()
'aWB is now accessible from here
end sub
In the class module where you have the application variable:
Private Sub App_WorkbookOpen(ByVal Wb As Excel.Workbook)
dTimeDefault = Now() + TimeValue("00:00:05")
set aWB=Wb
Application.OnTime dTimeDefault, "CreateNewWorksheet"
End Sub
Also, if you are using this technique to defer execution of some code
because of problems doing so in the WorkbookOpen procedure, you should be
able to use just Now() rather than impose a 5 second delay. It's a "trick"
I, myself, have used on more than a few occasions. Essentially,
Private Sub App_WorkbookOpen(ByVal Wb As Excel.Workbook)
set aWB=Wb
Application.OnTime Now(), "CreateNewWorksheet"
End Sub
--
Regards,
Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions