vba - how to return a value of variable from one module to another? -


1st module..

public sub directory_path() dim directory string     directory = inputbox("enter directory path contains folders ""this quarter"",""last quarter"",""second_last_quarter"".")     if right(directory, 1) = "\"     directory = left(directory, len(directory) - 1)     end if end sub 

i called the first module in 2nd module using public sub directory_path() . want directory variable in first module used variable in 2nd module... me. miss something... if question repeated, please answer me , delete post.

the obvious solution make function...

public function directory_path() sting     dim directory string     directory = inputbox("enter directory path contains folders " & _                 """this quarter"",""last quarter"",""second_last_quarter"".")     if right(directory, 1) = "\"         directory_path = left(directory, len(directory) - 1)     else         directory_path = vbnullstring     end if end function 

...and call function:

debug.print directory_path 

note instead of requiring user type path, can use filedialog instead:

public function directory_path() string     dim prompt filedialog     set prompt = application.filedialog(msofiledialogfolderpicker)     prompt         .title = "select directory path contains folders " & _                  """this quarter"",""last quarter"",""second_last_quarter""."         .allowmultiselect = false         if .show <> 0 directory_path = .selecteditems(1)     end end function 

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -