
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
difference between SUB and Function in vb scripting
I have a Macro code which starts with Sub Macroname........and in that code I am also having a Function FunctionNmae.......
when I try to run that macro.....should I use two names...I mean should I have to give triggers to run macro on both SUB and Function........
Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
A function executes code and returns a result, a sub only executes code but doesn't return a result. You should use subs for macros. Subs can call functions (and other subs). Try adding the code below in the macro editor and click the Test button.
Function TimesTwo(X)
TimesTwo = X+X
end function
Sub Add
result = TimesTwo(3)
msgbox result
end Sub
talk is cheap, supply exceeds demand

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
A function executes code and returns a result, a sub only executes code but doesn't return a result. You should use subs for macros. Subs can call functions (and other subs). Try adding the code below in the macro editor and click the Test button.
Function TimesTwo(X)
TimesTwo = X+X
end function
Sub Add
result = TimesTwo(3)
msgbox result
end Sub
talk is cheap, supply exceeds demand

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thankyou.....So if I have one Sub and two functions I need to run macro and give sub name and should not worry about the functions......

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, don't worry about the functions. Just use the subs for the run-macro actions
talk is cheap, supply exceeds demand

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thankyou Gysbert....I am still trying to send report after reload as email trough macro....I am not finding exact code.......I went trough community but did not find one........Can you Please help me out........
