+ Reply to Thread
Results 1 to 10 of 10

Call a beforesave macro in an email macro

  1. #1
    Registered User
    Join Date
    02-21-2013
    Location
    Ontario, Canada
    MS-Off Ver
    Office 2010
    Posts
    96

    Call a beforesave macro in an email macro

    Hi there,

    I have a beforesave macro that checks for any missing data that is required. It has message boxes that pop up and such to let users know they are missing data. I also have a mail macro where the user can press a submit button and it prompts the workbook to mail out. Obviously this mail macro does not have any sort of validation to check whether the required values are actually present. Is there any way i can call the beforesave macro into the mail macro?

    Code for Beforesave (In Workbook module)
    Please Login or Register  to view this content.
    Mail Macro (In Module 1)
    Please Login or Register  to view this content.

    Any help is appreciated.

    Thanks!

  2. #2
    Forum Contributor ragavan.sridar1's Avatar
    Join Date
    11-19-2012
    Location
    India
    MS-Off Ver
    Excel 2010, Excel 2003
    Posts
    208

    Re: Call a beforesave macro in an email macro

    May be you can try like

    Please Login or Register  to view this content.
    My guess is that as you already have an before save macro it will go and check it and then proceed with your email macro..

    again this is just a guess...
    Thanks!
    Raga.

    Please,mark your thread [SOLVED] if you received your answer.

    Click the little star * below, to give some Rep if you think an answer deserves it.

    I learnt so many things from these links.

  3. #3
    Registered User
    Join Date
    02-21-2013
    Location
    Ontario, Canada
    MS-Off Ver
    Office 2010
    Posts
    96

    Re: Call a beforesave macro in an email macro

    Quote Originally Posted by ragavan.sridar1 View Post
    May be you can try like

    Please Login or Register  to view this content.
    My guess is that as you already have an before save macro it will go and check it and then proceed with your email macro..

    again this is just a guess...
    Thanks for the quick reply man.

    I have this code already in my mail macro

    Please Login or Register  to view this content.
    It already has a saveas feature in it because it saves it to a temporary new file before emailing out then deleted the file after.

    I've tried using Option Private Module at the top then calling the beforesave macro using the following code:
    Please Login or Register  to view this content.
    I tried putting the Activeworkbook.save at the beginning and it starts to seem like it's working. But once it hits the above .saveas code for the mail portion, it seems to ignore the .save and proceeds with the email. Any ideas?

  4. #4
    Forum Contributor ragavan.sridar1's Avatar
    Join Date
    11-19-2012
    Location
    India
    MS-Off Ver
    Excel 2010, Excel 2003
    Posts
    208

    Re: Call a beforesave macro in an email macro

    did you try to add the before save macro as a module code and call it in the macro?

    like
    Please Login or Register  to view this content.
    and call this in your mail macro??

  5. #5
    Registered User
    Join Date
    02-21-2013
    Location
    Ontario, Canada
    MS-Off Ver
    Office 2010
    Posts
    96

    Re: Call a beforesave macro in an email macro

    Tried it and it still didn't work

    Also tried this:
    Please Login or Register  to view this content.
    This still didn't work. It seems to run through the beforesave code and displays the proper message boxes for fields missing but then once it gets to this point:
    Please Login or Register  to view this content.
    It's like this portion of the code ignores anything else in the macro. I need to add something right before that .saveas i think. Any ideas?

  6. #6
    Forum Contributor ragavan.sridar1's Avatar
    Join Date
    11-19-2012
    Location
    India
    MS-Off Ver
    Excel 2010, Excel 2003
    Posts
    208

    Re: Call a beforesave macro in an email macro

    do you want the users to enter all the required/correct values and then proceed to email?

  7. #7
    Registered User
    Join Date
    02-21-2013
    Location
    Ontario, Canada
    MS-Off Ver
    Office 2010
    Posts
    96

    Re: Call a beforesave macro in an email macro

    Quote Originally Posted by ragavan.sridar1 View Post
    do you want the users to enter all the required/correct values and then proceed to email?
    Yes that is the intent. Just like how right now if they are missing data when they go to Save the workbook, It will not save until all required data is entered. I want that to be the same with emailing. I don't know if it's giving me trouble because i'm saving to to a temporary file path & name - would that prevent the code from running properly? I have no idea. Stumped on this.

    Edit:

    Okay, i figured it out but now i have another issue which may be easier to address.
    Here is my code:
    Please Login or Register  to view this content.
    The bold is what i added to make this work. However, if the user forgets to put a value and hits the Mail button, It won't mail it and will give the error message but then it seems like all my macros and code just die and stop working. So the next time the user hits the Mail button (even if they are missing required data) it will send. The only way to fix this is to physically close excel (not just that workbook). If i have other spreadsheets going at the same time, i have to close those as well. Any way around this? Am i missing something like a Goto or Resume somewhere?

    Edit: HAHA. Fixed and solved. Ended up moving the bold portion right below the sub Mail_WO() before i defined my variables. It attempts to save it and if there is anything missing it exits the sub right there.

    Thanks for the help ragavan.
    Last edited by Spritz; 05-03-2013 at 01:04 PM. Reason: Solved

  8. #8
    Registered User
    Join Date
    02-21-2013
    Location
    Ontario, Canada
    MS-Off Ver
    Office 2010
    Posts
    96

    Re: Call a beforesave macro in an email macro

    Alright after playing around with this more i found out that it prevents mailing even if all required values are entered. I have it checking for an Error and if there is one it calls that exit sub routine. The only thing is, a message box isn't an error (correct me if i'm wrong) I'm not really sure how it is finding an error? but it does display the message box i have in the exit sub routine in bold.


  9. #9
    Forum Contributor ragavan.sridar1's Avatar
    Join Date
    11-19-2012
    Location
    India
    MS-Off Ver
    Excel 2010, Excel 2003
    Posts
    208

    Re: Call a beforesave macro in an email macro

    i've added both the codes together, when the details are not entered properly then it will ask the user to prompt whether they have entered the value incorrectly, if yes, it will end the macro else proceed to mailing.

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    02-21-2013
    Location
    Ontario, Canada
    MS-Off Ver
    Office 2010
    Posts
    96

    Re: Call a beforesave macro in an email macro

    Thanks Ragavan.

    That is exactly what i did. I just copied the code from each instance i needed it for (pdf, email, print) and it seems to be working perfectly.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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