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("to.com")
 Set emilCC = objMsg.Recipients.Add("cc.com")
 Set emilbcc = objMsg.Recipients.Add("bcc.com")
 emailTo.Type = olTo
 emailcc.Type = olCC
 emailbco.Type = olBCC
 emailTo.Resolve
 emailcc.Resolve
 emailBCC.Resolve
 objMsg.Display
 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.

regards

Shas
shasAsked:
Who is Participating?
 
Bill PrewCommented:
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.


»bp
1
 
shasAuthor Commented:
thank you very much for your reply Bill,

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

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

regards
Shas
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Bill PrewCommented:
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.


»bp
0
 
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.

regards
Shas
0
 
Bill PrewCommented:
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.


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

regards
Shas
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.