Solved

Pass VBA UserForm Selected  Listbox Item Value To ThisOutLookSession Module

Posted on 2014-03-24
5
4,739 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Large Outlook files lead to various unwanted errors and corruption issues. Furthermore, large outlook files can also make Outlook take longer to start-up, search, navigate, and shut-down. So, In this article, i will discuss a method to make your Out…
Mailbox Overload?
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

687 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