Results 1 to 3 of 3
  1. #1
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    suggestion... (2000 sr 1)

    i call a macro from a code for example:

    is a=b then call mymacro

    my friend suggest me to chaghe the head of mymacro inested sub mymacro() in function mymacro() in this mode i save memory, is correct?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: suggestion... (2000 sr 1)

    This seems to be more or less the same question as <post#=517781>post 517781</post#>. No, it doesn't make much difference.

  3. #3
    5 Star Lounger jujuraf's Avatar
    Join Date
    Jun 2001
    Location
    San Jose, California, USA
    Posts
    1,061
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: suggestion... (2000 sr 1)

    Your friend really doesn't know what he's talking about - he's confused.

    Macro = code = function = subroutine = procedure

    Technically they're not the same (and their definition also depends on what programming language you're talking about), but for the sake of this post (and your question) think of them as being the same thing -- and saving memory has nothing to do with it.

    You use a 'function' when you need to return an answer like x = myFunction("hello"), this does some work inside myFunction() and returns some information (whatever x holds). All Excel formulas are really functions since they return an answer "=sum(12+3)" this does the math and writes 15 into the cell where the formula is placed.

    You use a subroutine when you don't need to return an answer, all the work is self-contained w/in this procedure (block of code).

    sub myprocedure(data1 as integer, data2 as string)
    ' write code here
    end sub

    You use it just like you would any built-in Excel procedure such as Thisworkbook.protect "woody"

    ' some code here
    call myprocedure(12, "woody")
    ' other code here

    The 'call' keyword usually isn't needed but I personally prefer to use it as it makes it very clear it's code that you wrote and not an Excel built-in procedure.

    How much memory is used depends on what the code is (how it's written, what it does), not if it's a function vs. subroutine.

    Deb

Posting Permissions

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