+ Reply to Thread
Results 1 to 7 of 7

Can I convert a Macro to a Function?

  1. #1
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Question Can I convert a Macro to a Function?

    I have the below Macro that works beautifully (Thank you Leith), It finds updated data by current user and current date, then creates a new sheet with the new data. I have an RangetoHTML Function that is used for an automated email from a userform, which does not do what I am needing it to do. I am wondering if I can convert the following Macro to the RangetoHTML function, and if so, how difficult will it be? I have tried a few things, but all I did was mess everything up.
    Please Login or Register  to view this content.
    1N73LL1G3NC3 15 7H3 4B1L17Y 70 4D4P7 70 CH4NG3 - 573PH3N H4WK1NG
    You don't have to add Rep if I have helped you out (but it would be nice), but please mark the thread as SOLVED if your issue is resolved.

    Tom

  2. #2
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: Can I convert a Macro to a Function?

    http://www.excel-easy.com/vba/exampl...-function.html
    Please click the * below if this helps

  3. #3
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Can I convert a Macro to a Function?

    Jasper,
    Thank you for the response, but, I have tried to create the function myself. While it creates the sheet with the updated data as the above code does, which is what I want, when it sends the automated email that calls the RangetoHTML function to be placed in the body of the email, it doesn't work. It sends a blank email with a blank attachment. This is the reason I posted this thread, I am either doing something wrong (which is hopefully the case) or, what I want to do is not possible.
    *EDIT: I get a Type Mismatch error at the
    Please Login or Register  to view this content.
    Line
    Here is the Function code I tried, not much different from the above code...
    Please Login or Register  to view this content.
    Last edited by gmr4evr1; 07-11-2015 at 11:17 AM. Reason: Forgot part of the code

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

    Re: Can I convert a Macro to a Function?

    Tom

    What do you want the function to do?
    If posting code please use code tags, see here.

  5. #5
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Can I convert a Macro to a Function?

    I want it to email the newly created sheet with the updated information when the user clicks the send button on the userform. It creates the sheet and sends the email just fine, but when the email is sent, it is sent blank. On the Set ts = fso.Getfile line, I need it to pull the newly created sheet, not the workbook.

  6. #6
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Can I convert a Macro to a Function?

    OK, I figured out the type mismatch error and how to get the correct file (I think).

    Now I get a "Run-time error '62': Input past end of file" error at the following line...
    Please Login or Register  to view this content.
    Not sure what to do here.

  7. #7
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Can I convert a Macro to a Function?

    Solved per this thread
    http://www.excelforum.com/excel-prog...-with-vba.html
    Thank you Gregor Y

+ 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. Convert Worksheet Function to Macro?
    By BadDogTitan in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-16-2013, 11:09 PM
  2. Trying to Use a Convert function in a Macro
    By happyCal in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-05-2013, 02:12 PM
  3. Convert a SUMPRODUCT function to a macro
    By dreddster in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-13-2013, 04:10 AM
  4. how to convert a macro to function
    By thpr in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-17-2013, 05:18 AM
  5. convert iserror match function to macro
    By rooky in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-14-2010, 01:26 PM

Tags for this Thread

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