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
Solved

Pass VBA UserForm Selected  Listbox Item Value To ThisOutLookSession Module

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

This process describes the steps required to Import and Export data from and to .pst files using Exchange 2010. We can use these steps to export data from a user to a .pst file, import data back to the same or a different user, or even import data t…
Many people use more than one email account and so it becomes difficult for them to manage them when they use separate accounts,  so, in this article, I have shared an easy way to add Other Mail Accounts in your Google Inbox. It helps to combine all…
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…
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…

860 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