+ Reply to Thread
Results 1 to 7 of 7

How to use second procedure (the 2nd Sub) results in first procedure in the same module

  1. #1
    Forum Contributor
    Join Date
    11-12-2010
    Location
    HK
    MS-Off Ver
    Excel 2010
    Posts
    189

    How to use second procedure (the 2nd Sub) results in first procedure in the same module

    Hi all,

    I got a problem with using the result from Application.FileDialog (I wanna let the user to select a location to save) which is in the second procedure in a module. In my first procedure, I have to use the path that resulted from Application.FileDialog in the 2nd procedure.
    What should the code look like in the first procedure to use the result from the second procedure?

    Thanks
    Last edited by lubbamkt; 05-11-2014 at 10:18 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    07-04-2012
    Location
    Cape Town, RSA
    MS-Off Ver
    Office 365 ProPlus
    Posts
    1,050

    Re: How to use second procedure (the 2nd Sub) results in first procedure in the same modul

    You can use the Application.GetSaveAsFilename and assign it to a module level variable
    Then use that variable in the first macro

    Simplified code example:
    Please Login or Register  to view this content.
    Last edited by RudiS; 05-11-2014 at 06:24 AM.
    Regards,
    Rudi

  3. #3
    Forum Contributor
    Join Date
    11-12-2010
    Location
    HK
    MS-Off Ver
    Excel 2010
    Posts
    189

    Re: How to use second procedure (the 2nd Sub) results in first procedure in the same modul

    Quote Originally Posted by RudiS View Post
    You can use the Application.GetSaveAsFilename and assign it to a module level variable
    Then use that variable in the first macro

    Simplified code example:
    Please Login or Register  to view this content.
    Thanks RudiS,
    What if I would like to use FileDialog instead of GetSaveAsFilename? Do i need to use Function instead of Sub to run FileDialog in order to use the result in another Sub procedure?

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: How to use second procedure (the 2nd Sub) results in first procedure in the same modul

    Change the first Sub into Function that returns the directory/path the user has selected.

    You can then call the function from the second sub.

    If you post the code for the first sub I'll show you what I mean.
    If posting code please use code tags, see here.

  5. #5
    Forum Contributor
    Join Date
    11-12-2010
    Location
    HK
    MS-Off Ver
    Excel 2010
    Posts
    189

    Re: How to use second procedure (the 2nd Sub) results in first procedure in the same modul

    Quote Originally Posted by Norie View Post
    Change the first Sub into Function that returns the directory/path the user has selected.

    You can then call the function from the second sub.

    If you post the code for the first sub I'll show you what I mean.
    Norie, Here you are, Thanks
    Please Login or Register  to view this content.

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: How to use second procedure (the 2nd Sub) results in first procedure in the same modul

    You already have a function, but it's not returning a value.

    So you just need to add code to return the folder selected.
    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    11-12-2010
    Location
    HK
    MS-Off Ver
    Excel 2010
    Posts
    189

    Re: How to use second procedure (the 2nd Sub) results in first procedure in the same modul

    Quote Originally Posted by Norie View Post
    You already have a function, but it's not returning a value.

    So you just need to add code to return the folder selected.
    Please Login or Register  to view this content.
    Thank you Norie

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. How to run a separate private procedure within the same module
    By clemsoncooz in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-16-2012, 05:07 PM
  2. Remove and add Module or Procedure in Outlook with vba
    By wotadude in forum Outlook Programming / VBA / Macros
    Replies: 0
    Last Post: 01-19-2011, 04:01 PM
  3. Error calling a procedure not in a module
    By maacmaac in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-14-2009, 03:03 AM
  4. [SOLVED] get module line from erl and procedure
    By RB Smissaert in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-16-2006, 09:50 PM
  5. [SOLVED] Add Procedure To Module Via VBA
    By Al in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-20-2005, 06:06 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1