how to program a outlook VBA userform to create another macro on the same machine

Hello all,

is it possible to create a macro which can be used to create/insert another macro/sub procedure in VBA on the same machine?

like this

suppose, an outlook vba userform with fields like "macroName, To, CC and BCC"

when user load this userform and update these fields, a new macro (sub procedure) wants to be created on the same machine like below

Sub macroName()
 Dim objMsg As MailItem
 Dim emilTo As Outlook.Recipient
 Dim emilCC As Outlook.Recipient
 Dim emailBCC As Outlook.Recipient
 Set objItem = Application.ActiveInspector.CurrentItem
 Set objMsg = objItem.Forward
 Set emilTo = objMsg.Recipients.Add("")
 Set emilCC = objMsg.Recipients.Add("")
 Set emilbcc = objMsg.Recipients.Add("")
 emailTo.Type = olTo
 emailcc.Type = olCC
 emailbco.Type = olBCC
 End Sub

so if I create let's say a main/standard vba userform (a forwarding macro in above case) to be used by an end user who probably unknown to vba codlings can create a number of forwarding macros with different recipients. further if these new macros can be assigned to customized button programmatically, it would be wonderful.


Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bill PrewIT / Software Engineering ConsultantCommented:
Sorry to deliver the bad news, but you are not going to be able to easily accomplish that.  Some of the other Office applications, like Excel, do allow access to the Visual Basic Editor (VBE) programmaticly so that VBA code can modify / add other VBA modules and code.  But that is not allowed in Outlook, most likely for security reasons.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
shasAuthor Commented:
thank you very much for your reply Bill,

even it's a bad news, you saved a lot of my time.
shasAuthor Commented:
Dear Bill

could you please guide me if it (accessing outlook VBE) is possible using visual studio add-ins or other application

Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Bill PrewIT / Software Engineering ConsultantCommented:
What are you really trying to accomplish?  I don't believe you can do this with VSTO either in Visual Studio.  If you went that way, you would have to implement a COM approach using VSTO rather than a VBA approach.

You can however edit / add to the VbaProject.OTM file, when Outlook is not running.  But I don't think that really accomplishes your need.

It sounds like you want the end user to be able to configure certain values that would be used in a Rule.  Perhaps you could approach this differently and write the rule as generic always using the same code, and then place the variable values that the user can configure in a "database" of sorts (could just be a flat file).  Then the form you are building allows changes to that data, and the rule reads that data and uses the values for processing.  My only concern there might be performance, since the rule would now be loading this information each time it fired.

Just some thoughts.

shasAuthor Commented:
thanks again for your reply.

here is what I really want to do:

I created some forwarding macros for my colleague to forward certain incoming email to appropriate multiple recipients with a customized button on the Quick Access Toolbar. I also created some other macros too that just open a saved email template with pre-formatted and recipients.  my colleague is very happy to save lot of his time & effort

My colleague receives really bulk email everyday, so he wants more macros with some different criteria (ie, a copy of the first macro with changes only in template's name or set of recipients)

 now I m looking some easy method for my colleague so that he can create appropriate macro by himself without manually access VB editor for writing/copying the codes and customize quick access toolbar button.

Bill PrewIT / Software Engineering ConsultantCommented:
Okay, I guess my earlier comment still stands then.  If you really want to have some sort of user configurable rules, then I think you will have to create an additional data store that houses the criteria and actions data, and then develop a central standard rule that uses that data to make decisions when email comes in.  I haven't searched around, but I don't have any examples of code using that approach that I can share.

shasAuthor Commented:
Thank you Bill. I really appreciate your effort

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.