Solved

Pass VBA UserForm Selected  Listbox Item Value To ThisOutLookSession Module

Posted on 2014-03-24
5
4,567 Views
Last Modified: 2014-03-28
In Outlook 2007 I have created a VBA UserForm (UserForm1) on which I have placed a single-column Listbox control (Listbox1).  I populate the Listbox conrol with the FullName of each Contact that is present in the Contacts folder.  This works without problem.

When I select one of the Contacts in the Listbox located on the VBA UserForm (Listbox1), I need to pass the value for the selected Listbox item to the VBA code running in the ThisOutlookSession module.  Is this even possible?  If so, what does the code look like?

Thanks,

Bill Vallance
0
Comment
Question by:bvallanc
  • 3
  • 2
5 Comments
 
LVL 3

Accepted Solution

by:
englanddg earned 400 total points
ID: 39952005
In your sub in your module, you can use UserForm1.ListBox1.Value to call the value selected in the ListBox.

Here's a sample of what I mean.

Open a blank spreadsheet.  Create a module (We'll call it Module1).  Add this code.

Sub test()
    MsgBox (UserForm1.ListBox1.Value)
End Sub

Open in new window


Create a userform.  We'll call it UserForm1.  To that add a Listbox (called ListBox1) and a Command Button (CommandButton1)

Then, in the FORM code, add this code.

Private Sub CommandButton1_Click()
    Call test
End Sub

Private Sub UserForm_Initialize()
    ListBox1.AddItem ("test1")
    ListBox1.AddItem ("test2")
End Sub

Open in new window


As you can see, I'm using the command button on click event to call the test sub in the module.  Then calling the selected value of the listbox and displaying it in a message box in the test sub.

Hope this helps!
0
 

Author Comment

by:bvallanc
ID: 39952213
This works when the code is created in a Module.  It doesn't seem to work if the code is created in ThisOutLookSession (I've created all of my code (so far) in ThisOutLookSession).  Is this correct?
0
 
LVL 3

Expert Comment

by:englanddg
ID: 39952232
Do you mind posting your code?

As far as I know, a public module is the best solution.  At least...it's the solution that will work!
0
 

Author Comment

by:bvallanc
ID: 39963126
Thanks, englanddg, for your answer.  I was hoping that someone would specifically answer my question about how to communicate between a standard Module and the ThisOutLookSession module.  Since I have taken your advice and placed my code in a standard Module I think it's fair to award 50% of the points for your time and effort.

Thanks for your help!

Bill Vallance
0
 

Author Comment

by:bvallanc
ID: 39963129
Englanddg, you got all 400 points because I don't have the time to screw around with allocating points.  Thanks so much for your help with this problem.
Regards,

Bill Vallance
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes Outlook might have problems sending a message. There may be various causes- corrupted PST, AV scanner etc. The message, instead of going to the Sent Items folder, sits in the Outbox indefinitely. To remove it you can use a free tool cal…
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now