Consulting

Results 1 to 11 of 11

Thread: Solved: ready to try functions

  1. #1
    VBAX Regular dvenn's Avatar
    Joined
    Jun 2005
    Posts
    41
    Location

    Solved: ready to try functions

    okay.. having learned so much from here... I think I am ready to move into functions..

    Here is what I want to try...

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

    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

    [VBA]doStuff somemacro[/VBA]

    compile Error:

    expected Function or variable

    Daniel Venn
    Office2003 on Win2K & WinXPSP2

    Most people learn by observation, and there are the few who learn by experimentation. And then there are those who actually TOUCH the fire to see if it's really hot.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    It should be a string, because OnTime takes a string parameter, the name of the proc.

  3. #3
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    If you are trying to pass a string try enclosing it in quotes.

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    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.

  5. #5
    VBAX Regular dvenn's Avatar
    Joined
    Jun 2005
    Posts
    41
    Location
    can you pass a string to a sub?
    Daniel Venn
    Office2003 on Win2K & WinXPSP2

    Most people learn by observation, and there are the few who learn by experimentation. And then there are those who actually TOUCH the fire to see if it's really hot.

  6. #6
    VBAX Regular dvenn's Avatar
    Joined
    Jun 2005
    Posts
    41
    Location
    Also I tried enclosing the proc with " "

    [VBA] doStuff "somemacro"
    [/VBA]

    But now I get an object required error on

    [VBA] Applications.OnTime Now + TimeValue("00:00:01"), Proc [/VBA]

    Getting closer
    Daniel Venn
    Office2003 on Win2K & WinXPSP2

    Most people learn by observation, and there are the few who learn by experimentation. And then there are those who actually TOUCH the fire to see if it's really hot.

  7. #7
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Like this

    [vba]
    Sub CallerProc()
    myOtherProc "Bob"
    End Sub

    Sub myOtherProc(nme As String)
    MsgBox nme
    End Sub
    [/vba]

  8. #8
    VBAX Regular dvenn's Avatar
    Joined
    Jun 2005
    Posts
    41
    Location
    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
    Daniel Venn
    Office2003 on Win2K & WinXPSP2

    Most people learn by observation, and there are the few who learn by experimentation. And then there are those who actually TOUCH the fire to see if it's really hot.

  9. #9
    VBAX Regular dvenn's Avatar
    Joined
    Jun 2005
    Posts
    41
    Location
    okay (hangs head in shame) found the error...

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

    Applications.onTime.. darn Typo..
    Daniel Venn
    Office2003 on Win2K & WinXPSP2

    Most people learn by observation, and there are the few who learn by experimentation. And then there are those who actually TOUCH the fire to see if it's really hot.

  10. #10
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi Daniel,
    I posted an OnTime code here yesterday
    http://www.vbaexpress.com/forum/show...29&postcount=5
    Regards
    MD
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  11. #11
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by dvenn
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •