Solved

Pass VBA UserForm Selected  Listbox Item Value To ThisOutLookSession Module

Posted on 2014-03-24
5
4,508 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Learn more about how the humble email signature can be used as more than just an electronic business card. When used correctly, a signature can easily be tailored for different purposes by different departments within an organization.
Set OWA language and time zone in Exchange for individuals, all users or per database.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

757 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

20 Experts available now in Live!

Get 1:1 Help Now