-
Solved: Use of Userform rather than MSGBOX in Outlook VBA
I have seen many examples of the Application_ItemSend where data is entered by the user through the standard MSGBOX. I want to use a userform to gather data and pass it back to the VBA module but the variables I am assigning data to go out of context when the userform is closed.
Can anyone suggest a solution whereby I can call a userform, initilize it, have the user enter the data, then pass that data using public variables back to the ItemSend module.
Thanks in advance
Brian H.
-
You can use a Global variable, declared at the top of a Module. Or when the data is entered in the userform instead of Unloading it, just hide it first, get the data from it, then Unload it from the Module.
-
Thanks jake,
I actually tried that, defining the global variable as intResponse in the ThisOutlookSession object like this
Public intResponse.
This was where I got to when I posted the msg.
If I try
Global intResponse, I get
"Constants, fixed-length strings, arrays, user-defined types, and Declare statements not allowed as Public members of an object module"
I also tried to define the global variable in the userform code but I get the same issue.
Perhaps this is one of those quirks to do with how Outlook handles VBA modules.
What I am trying to achieve is.
Before an email is sent I want outlook to check for a string in the subject line. If the string is not found, I want to pop up a dialog that provides two options (strings) to insert in the subject line. I can achieve this using MsgBox (Yes = String1, No=String2) but it looks tacky.
Brian H.
-
You have to put it in a Module.
[VBA]
Option Explicit
Global x As String
Sub Macro1()
x = "Hi"
UserForm1.Show
End Sub
[/VBA]
The add a UserForm called UserForm1 and put in this code:
[VBA]
Option Explicit
Private Sub UserForm_Click()
MsgBox x
End Sub
[/VBA]
-
Thanks Jake,
That did the trick. I did not think of creating a separate module. Now I have a module that does all the work. I simply call the procedure from the This OutlookSession object and it works fine.
Brian H.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules