+ Reply to Thread
Results 1 to 12 of 12

call function from within a sub

  1. #1
    Registered User
    Join Date
    11-29-2018
    Location
    Uk
    MS-Off Ver
    365
    Posts
    9

    call function from within a sub

    Hi Thanks for looking at this.
    i have a function to check a worksheet and return a string (Answer)that i can use in a sub to create a word document and set some customDocumentproperites.
    Each block of code works but i would welcome help of how to get the string produced by the function written into the sub.
    Answer produces the string required



    Please Login or Register  to view this content.
    Last edited by TryHarder; 11-29-2018 at 12:15 PM.

  2. #2
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: call function from within a sub

    Your post does not comply with Rule 2 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Click on Edit to open your thread, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 6)
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  3. #3
    Registered User
    Join Date
    11-29-2018
    Location
    Uk
    MS-Off Ver
    365
    Posts
    9

    Re: call function from within a sub

    Arkadi
    Thanks for pointing this out i understand now

  4. #4
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: call function from within a sub

    Thanks very much for fixing that TryHarder, and welcome to the forum

    I wonder why you have a global variable "Answer" is that to try and get the Answer into the sub? It should not be needed.

    Just dim a variable as a string in your SUB, and within the sub make it equal the function....

    Small changes to the function:

    Please Login or Register  to view this content.
    Then in the Sub:

    Please Login or Register  to view this content.
    At this poing myString should have the result from GetAnswer as its value, and you can use it as needed.
    Last edited by Arkadi; 11-29-2018 at 01:09 PM.

  5. #5
    Registered User
    Join Date
    11-29-2018
    Location
    Uk
    MS-Off Ver
    365
    Posts
    9

    Re: call function from within a sub

    Arkadi
    Thank you for your prompt reply.
    i have made your changes and my string returns a value.(That is Great)

    however it only returns the last value from the loop.

    Please Login or Register  to view this content.
    This is great but that value is not passed to the new document.
    however if i paste that line in it works fine.
    Do you have any ideas please?

  6. #6
    Registered User
    Join Date
    11-29-2018
    Location
    Uk
    MS-Off Ver
    365
    Posts
    9

    Re: call function from within a sub

    Arkadi

    Thank you answering my question.
    i can now see how to return the value.
    I will try to work out how to make the calling routine work with it and if need be ask another question.

    Best Regards
    TryHarder

  7. #7
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: call function from within a sub

    Sorry, haven't looked since I posted... I'll have a look in a couple of minutes

  8. #8
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: call function from within a sub

    I need to better understand what your desired result is....
    Do you want the returned value to be multiple lines of text?

    If so then try this:

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    11-29-2018
    Location
    Uk
    MS-Off Ver
    365
    Posts
    9

    Unhappy Re: call function from within a sub

    Arkadi,
    Thank you for your further help , i am sorry that i have only just seen it.
    Your code works fine and returns to a msgbox the text that is needed.
    Thanks for explaining for it works.

    What i am trying to do with the returned text is to set a list of customDocumentProperties within the code to produce a new word document created from a template.
    Please Login or Register  to view this content.

    Do i need to call another function to run the code ?

    I am sorry that i did not make this clear to start with.

  10. #10
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: call function from within a sub

    Hope I have understood correctly....

    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    11-29-2018
    Location
    Uk
    MS-Off Ver
    365
    Posts
    9

    Re: call function from within a sub

    Arkadi,
    what a great answer thank you for your ongoing efforts ,
    it works just fine and is clear and easy to understand.

    Thank you again.
    Best Regards

    Tryharder

  12. #12
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: call function from within a sub

    Hi TryHarder,

    I'm glad it worked out for you, and appreciate your feedback. It is always nice to help people find a good solution to their question/problem. Take care, and see you next time

+ 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. Replies: 2
    Last Post: 06-03-2014, 03:44 AM
  2. How to call a xls-function from an add-in
    By JKG in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 05-31-2010, 10:18 AM
  3. Is it possible to call a function as a Variable(Parameter) of an other function in VB
    By vsidharth in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-25-2009, 05:25 PM
  4. cannot call the function
    By thy00123 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-05-2009, 07:13 AM
  5. Call Function by Name
    By arbus in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 09-03-2007, 04:25 AM
  6. Call a Function
    By Desert Piranha in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-14-2006, 11:13 PM
  7. Call Sub from Function?
    By G Lykos in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-23-2005, 02:48 AM

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