+ Reply to Thread
Results 1 to 10 of 10

Modify a Module with a Userform?

  1. #1
    Forum Contributor
    Join Date
    09-10-2008
    Location
    Phoenix, AZ
    MS-Off Ver
    Office 365
    Posts
    985

    Modify a Module with a Userform?

    Hi there everyone,

    I have an interesting question... I have an email module that sends an email from the worksheet. The Module has predetermined information.

    Is it possible for a UserForm to be used to change the data in the Module IE:


    Please Login or Register  to view this content.
    Regards, John
    Last edited by JJFletcher; 11-30-2021 at 01:52 PM.

  2. #2
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: Modify a Module with a Userform?

    All depends on where John, Peter and New derive from.
    Are you looking at a "mail merge" situation here?

    Post a sample workbook, it will help greatly.

    BSB

  3. #3
    Forum Contributor
    Join Date
    09-10-2008
    Location
    Phoenix, AZ
    MS-Off Ver
    Office 365
    Posts
    985

    Re: Modify a Module with a Userform?

    Here is the code.... It works fantastic as it is, I just want to automate the process by letting the user change the To:, CC:, Subject lines of the Module

    Please Login or Register  to view this content.
    Regards,

    John

  4. #4
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: Modify a Module with a Userform?

    Change it at what point and in what manner?

    Keep in mind we have no idea what your workbook does, other than the code above. We have no idea of data layout or purpose.

    Do you want input boxes to add email addresses? Should they come from a predefined list? What's wrong with just dispaying the email without those field filled in and let the user to that at that point?

    Too may questions....

    BSB

  5. #5
    Forum Contributor
    Join Date
    09-10-2008
    Location
    Phoenix, AZ
    MS-Off Ver
    Office 365
    Posts
    985

    Re: Modify a Module with a Userform?

    BSB -

    Great suggestion... I will give that some consideration.....

    Just thought there may be a way to overwrite that section in the module and then the user only needs to do the entry once... the module pulls the data from the specified ranges in the worksheet... easy peasy...

    If anyone has a suggestion I will gladly appreciate it!!!

    Regards,

    John
    Last edited by JJFletcher; 11-27-2021 at 05:49 PM.

  6. #6
    Forum Contributor
    Join Date
    09-10-2008
    Location
    Phoenix, AZ
    MS-Off Ver
    Office 365
    Posts
    985

    Re: Modify a Module with a Userform?

    Great suggestion... I will give that some consideration.....

    Just thought there may be a way to overwrite that section in the module and then the user only needs to do the entry once... the module pulls the data from the specified ranges in the worksheet... easy peasy...

    If anyone has a suggestion I will gladly appreciate it!!!

    Regards,

    John

  7. #7
    Forum Contributor
    Join Date
    10-02-2012
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    251

    Re: Modify a Module with a Userform?

    Hi JJ, you can declare different variables such as strings, integers, arrays etc outside of any code.

    At the very top of your forms code (before the subs etc) enter;
    Please Login or Register  to view this content.
    Then create your form controls, place your 3 textboxes and a command button, and in your command button put the following;
    Please Login or Register  to view this content.
    Then change your existing sub to this;

    Please Login or Register  to view this content.
    Make sure your subs are Public, not private.

    Hope this helps
    Last edited by PrizeGotti; 11-29-2021 at 08:38 AM.

  8. #8
    Forum Contributor
    Join Date
    09-10-2008
    Location
    Phoenix, AZ
    MS-Off Ver
    Office 365
    Posts
    985

    Re: Modify a Module with a Userform?

    Hello PG,

    Thanks for your suggestion, it looks very promising..

    I tried to implement your code as suggested and did not get the results of the To, CC, Subject proposed being able to change in the module.

    Possibly I am creating the code wrong.

    When placing the Option Public Module I get an error and the text ( Option Public Module ) turns red. And a popup warning saying Compile Error. Expected: Base or Compare or explicit or Private...

    Possible suggestion or maybe you have a sample workbook showing this functioning?

    Best Regards,

    John
    Last edited by JJFletcher; 11-29-2021 at 04:56 PM.

  9. #9
    Forum Contributor
    Join Date
    09-10-2008
    Location
    Phoenix, AZ
    MS-Off Ver
    Office 365
    Posts
    985

    Re: Modify a Module with a Userform?

    Okay everyone,

    I re wrote PG's code and now it works and processes the email just fine... However, the goals is to get the EmailTo, EmailCC, and EmailSubject to be changed in the module.

    The code does function and produces an email and that is great, but the module "Public Sub Mail_Selection_Range_Outlook_Body" will do the email.

    Any suggestions??

    Best Regards,

    John

  10. #10
    Forum Contributor
    Join Date
    10-02-2012
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    251

    Re: Modify a Module with a Userform?

    Quote Originally Posted by JJFletcher View Post
    Okay everyone,

    I re wrote PG's code and now it works and processes the email just fine... However, the goals is to get the EmailTo, EmailCC, and EmailSubject to be changed in the module.

    The code does function and produces an email and that is great, but the module "Public Sub Mail_Selection_Range_Outlook_Body" will do the email.

    Any suggestions??

    Best Regards,

    John
    I might be wrong, but I don't believe it is actually possible to edit a module or any bit of code through the use of the code itself. Doing so could allow people to manipulate the code to either exploit or break it.

    I'm assuming this is because when you open the sheet it no longer remembers what "EmailTo, EmailCC, and EmailSubject" are set to?

    My only solution to this is to create a "helper" sheet, one hidden away but stores variables for use. You would have to change the code to write these values to the cells you select, rather than assign them to the variables. Then in your email macro, change "EmailTo, EmailCC, and EmailSubject" to the cells you chose on the helper sheet.

+ 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. [SOLVED] how to use userform variables with module macro
    By dmcgov in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-20-2019, 03:57 PM
  2. Place code in userform, module or class module
    By nigelog in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-16-2017, 07:04 AM
  3. [SOLVED] Value in textbox in userform to check with a dynamic range in module macro
    By flabb in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-15-2016, 05:55 AM
  4. [SOLVED] Creating a macro (or module) to modify a cell's value based on automated entries
    By Julez80s in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-22-2012, 01:51 PM
  5. Create a macro (module?) that activates in my userform code?
    By Bafa in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-17-2008, 09:15 PM
  6. accessing array of an userform from a Sheet/module macro code
    By stanigator in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-19-2007, 09:34 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