unloading a function

I have a question i am writing a program in Outlook. I have a button on a userform that when I click it I want to unload a function in a module from memory. I thought I could just put this in the click event:

Unload Project1.Module_Name.Function_Name

However, that just runs the function again.

Also, I would like to know, is there any way in vba to say "unload all functions and subroutines"

Anyone got any ideas

thanks,

Dudeman


Answer this question

unloading a function

  • pant

    Hi Dudeman,

    I think the only way you can maybe do this is if the code is part of a class module but even then I'm not sure. You'd unload the class then. Still not sure if the Unload method would do it though.

    In VBA doesn't the memory used by an object get destroyed after the object goes out of scope I've never heard of unloading a function, just curious but why are you doing it



  • TimSpencer

    Hi Dudeman,

    You can exit a function by calling Exit Function or Exit Sub.

    Your user form won't be able to directly cause the macro that loaded it to exit.

    Instead you need an if statement in the macro that displays the form. The if statement checks if the button on the form was pressed, if it was call Exit Function.

    here bButtonPressed is a public boolean thats set to true when the user presses the button.

    If (UserForm.bButtonPressed = True) then

    Exit Function

    End if



  • Carlos Guzmán Álvarez

    Thanks, that works perfect, exactly what I needed.
  • Raptor0001

    I am running this function and then halfway through the function I show a userform. If the user clicks on a certain button on that userform, I want to exit the function.
  • unloading a function