PDA

View Full Version : Solved: ready to try functions



dvenn
02-23-2006, 02:15 PM
okay.. having learned so much from here... I think I am ready to move into functions..

Here is what I want to try...

Public Function DoStuff (Proc as ??)
Load userform1
Applications.OnTime Now + TimeValue("00:00:01"), Proc
End Function


Proc = a macro name..

The userform actually watches the macros run.. and captures information (I have that part), and until now I was running this as a sub.. but I added another routine that I want the user form to watch... so instead of doing seomthing like adding a second copy of the sub.. i thought "If I could pass the maro name to a function then I wouldn't need to do that.."

anyways.. I tried as String, as Variant, & as Object but I get and error on the line in the macro

doStuff somemacro

compile Error:

expected Function or variable

:help

Bob Phillips
02-23-2006, 02:24 PM
It should be a string, because OnTime takes a string parameter, the name of the proc.

Norie
02-23-2006, 02:24 PM
If you are trying to pass a string try enclosing it in quotes.

Bob Phillips
02-23-2006, 02:25 PM
BTW, it doesn't hurt, but it doesn't need to be a function. Functions are usually used to return a result to the caller.

dvenn
02-23-2006, 02:26 PM
can you pass a string to a sub?

dvenn
02-23-2006, 02:32 PM
Also I tried enclosing the proc with " "

doStuff "somemacro"


But now I get an object required error on

Applications.OnTime Now + TimeValue("00:00:01"), Proc

Getting closer :)

Bob Phillips
02-23-2006, 02:35 PM
Like this


Sub CallerProc()
myOtherProc "Bob"
End Sub

Sub myOtherProc(nme As String)
MsgBox nme
End Sub

dvenn
02-23-2006, 02:45 PM
had tried that but when I was getting the errors I thought maybe i needed a function for it...

Still getting the object required errror with both function and sub

dvenn
02-23-2006, 03:12 PM
okay (hangs head in shame) found the error...

thanks for not laughing at me too hard.. (at least publically :))

Applications.onTime.. darn Typo..

mdmackillop
02-23-2006, 03:24 PM
Hi Daniel,
I posted an OnTime code here yesterday
http://www.vbaexpress.com/forum/showpost.php?p=58329&postcount=5
Regards
MD

Bob Phillips
02-23-2006, 03:53 PM
okay (hangs head in shame) found the error...

thanks for not laughing at me too hard.. (at least publically :))

Applications.onTime.. darn Typo..

LOL. Didin't spot that.