UserForm Code For Contact Links

Status
Not open for further replies.
Thank you. I looked at it and I believe that is not the way to upgrade. One other question just in case you think this makes more sense.

In the current code as to:

For Each fldr In objFolder.Folders. It is the subfolders

And

For Each flder In fldr.Folders. Its the subfolders of the subfolders.

So specifically, what to add so its the subfolders of the subfolders of the subfolders? As this would go thru the third level subfolders.

Thanks very much!
 
Here is what I updgraded as I posted next (as there is a limitation on the number of letters in each post), and it takes care of the third level subfolders
 
Private Sub ddlCategories_Change()
Dim objOutlook As Outlook.Application
Dim objNS As Outlook.NameSpace
Dim objFolder As Outlook.MAPIFolder
Dim ctc As ContactItem
Dim FolderName As String
Dim fldr As Folder
Dim flder As Outlook.Folder
Dim flderr As Outlook.Folder
Dim myContacts As Outlook.items
Dim Category As String
Category = Me.ddlCategories.Text

Set objOutlook = CreateObject("Outlook.Application")
Set objFolder = objOutlook.Session.GetDefaultFolder(OlDefaultFolders.olFolderContacts)

Me.ddlContacts.Clear

If objFolder.Folders.Count > 0 Then
For Each fldr In objFolder.Folders
Set myContacts = fldr.items.Restrict("[Categories] = '" & Category & "'")
If myContacts.Count > 0 Then
myContacts.Sort "[Fullname]", False

For Each ctc In myContacts
Me.ddlContacts.addItem ctc.FullName
Next
End If

For Each flder In fldr.Folders
Set myContacts = flder.items.Restrict("[Categories] = '" & Category & "'")
If myContacts.Count > 0 Then
myContacts.Sort "[Fullname]", False

For Each ctc In myContacts
Me.ddlContacts.addItem ctc.FullName
Next
End If

For Each flderr In flder.Folders
Set myContacts = flderr.items.Restrict("[Categories] = '" & Category & "'")
If myContacts.Count > 0 Then
myContacts.Sort "[Fullname]", False

For Each ctc In myContacts
Me.ddlContacts.addItem ctc.FullName
Next
End If
Next
Next
Next

End If


End Sub
 
Private Sub UserForm_Initialize()
'The loads the Outlook userform and populates the combobox of contact folders.

Dim objOutlook As Outlook.Application
Dim objNS As Outlook.NameSpace
Dim objFolder As Outlook.MAPIFolder
Dim Category
Set objOutlook = CreateObject("Outlook.Application")

For Each Category In Application.Session.Categories
Me.ddlCategories.addItem Category
Next




End Sub

Private Sub ddlContacts_Change()
'This opens the contact form for the contact selected.
Dim objOutlook As Outlook.Application
Dim objNS As Outlook.NameSpace
Dim ctcItems As Outlook.items
Dim ctc As ContactItem
Dim objFolder As Outlook.MAPIFolder
Dim ctcFolder As Outlook.MAPIFolder
Dim FolderName As String
Dim ContactName As String
Dim FoundFolder As Outlook.Folder

Set objOutlook = CreateObject("Outlook.Application")
Set objFolder = objOutlook.Session.GetDefaultFolder(OlDefaultFolders.olFolderContacts)

ContactName = Me.ddlContacts.Text

If objFolder.Folders.Count > 0 Then
For Each fldr In objFolder.Folders
Set ctcItems = fldr.items.Restrict("[FullName] = '" & ContactName & "'")
If ctcItems.Count > 0 Then
Me.Hide
For Each ctc In ctcItems
ctc.Display
Next
Exit Sub
Else
For Each flder In fldr.Folders
Set ctcItems = flder.items.Restrict("[FullName] = '" & ContactName & "'")
If ctcItems.Count > 0 Then
Me.Hide
For Each ctc In ctcItems
ctc.Display
Next
Exit Sub

Else

For Each flderr In flder.Folders
Set ctcItems = flderr.items.Restrict("[FullName] = '" & ContactName & "'")
If ctcItems.Count > 0 Then
Me.Hide
For Each ctc In ctcItems
ctc.Display
Next
Exit Sub

End If
Next
End If
Next

End If

Next

End If


End Sub

Private Function FullFolderName(ByVal FolderName As String) As Outlook.Folder


End Function
 
Now also, when the contacts list shows up, they are sorted alphabetically per each subfolder they come from....so is there a way to show them all alphabetically as if from just one folder?
 
For Each fldr In objFolder.Folders. It is the subfolders

And

For Each flder In fldr.Folders. Its the subfolders of the subfolders.

So specifically, what to add so its the subfolders of the subfolders of the subfolders? As this would go thru the third level subfolders.

wouldn't it be like this:

For Each whatever In flder.Folders
 
Now also, when the contacts list shows up, they are sorted alphabetically per each subfolder they come from....so is there a way to show them all alphabetically as if from just one folder?

No, not when you do one folder at a time.

Because its so difficult to do anything with the things in separate folders, outlook mvps always recommend using fewer folders and categories.
 
Thats what i did per what i showed above. And had to add a few other things re the other areas.

So anything on the sort all per alphebetically?
 
You'd need to read the folder contents into an array then sort the array. It can be very slow if you have a lot of records. And i don't have any code samples - most are for excel workbooks.

http://vbaexpress.com/kb/getarticle.php?kb_id=103 has an example, but you need to create an array.
 
This is one way to create an array. (report is the array)

Public Sub ListContacts()

Dim Session As Outlook.NameSpace
Dim Report As String
Dim ContactFolder As Outlook.folder
Dim currentItem As Object
Dim currentContact As ContactItem
Set Session = Application.Session

Set ContactFolder = Session.GetDefaultFolder(olFolderContacts)

For Each currentItem In ContactFolder.Items
If (currentItem.Class = olContact) Then
Set currentContact = currentItem
If ("Full Name" <> "") Then
Report = Report & """" & currentContact.FullName & """, "
End If
End If

Next

Debug.Print Report


End Sub
 
Thanks so much. Where do i put the code you gave me regarding the code i use!
 
I have no idea. :) It's just a sample to should you how to do it. I'm not sure it will be the most efficient with a lot of folders.

this is the meat of the code - you'd walk each folder and add to the array. But like i said, it's probably going to be very slow if you have a lot of folders and contacts.

Set ContactFolder = Session.GetDefaultFolder(olFolderContacts)
For Each currentItem In ContactFolder.Items
If (currentItem.Class = olContact) Then
Set currentContact = currentItem
If ("Full Name" <> "") Then
Report = Report & """" & currentContact.FullName & """, "
End If
End If
Next
 
Got it! Happy to get a sugestion you might think about.
 
As to referring to the to Contact folder and not subfolders.....as to the following code, instead of referring to "For Each fldr in objFolder.Folders", how do I refer to the standard Contact folder ....so I can categorize contacts in the Contact folder as well...fo purposes of my list

For Each fldr In objFolder.Folders
Set myContacts = fldr.Items.Restrict("[Categories] = '" & Category & "'")
If myContacts.Count > 0 Then
myContacts.Sort "[Fullname]", False

For Each ctc In myContacts
Me.ddlContacts.addItem ctc.FullName
Next
End If
 
That would be

Set objFolder = objOutlook.Session.GetDefaultFolder(OlDefaultFolde rs.olFolderContacts)

Set myContacts = objFolder.Items.Restrict("[Categories] = '" & Category & "'")
 
Thanks very much....if you look at my full code, where do I put this as there is that place where it is the subfolder(s) process and not sure do I put that in there...or above it?
 
It would go just above it.
 
I emailed you the full code and explained how there are two places...as the contacts from the cagegory and the link to the contacts later in the code...if you can, plesae read my email as its two large to post
 
I just emailed you the entire new code that I figured out and it does it all......so the only thing left is the sorting by alphabetical across all category lists and all contact list that shows up.....so if you look at my big email, you can understand how I used a portion of what you gave me and everything else I changes or added....and again, so the only thing left is the sorting by alphabetical across all category lists and all contact list that shows up
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
R Adding Userform Dropdown List items from names of subfolders on network drive Outlook VBA and Custom Forms 10
A Outlook Userform Size Outlook VBA and Custom Forms 2
N Activity Tracking with Userform Outlook VBA and Custom Forms 4
D Next Available Meeting with Userform Variables Outlook VBA and Custom Forms 1
A Populate Excel from Outlook Userform Outlook VBA and Custom Forms 3
B Insert Hyperlinks for attachments in Userform Outlook VBA and Custom Forms 5
D Change sender name outlook vba 2010 Custom Userform Outlook VBA and Custom Forms 1
A Open CHM file from VBA Userform Outlook VBA and Custom Forms 4
L Outlook 2007 - Userform Using Outlook 2
A Focus on the userform Outlook VBA and Custom Forms 15
F Outlook 2010 - outlook userform and combo boxes Using Outlook 9
L Userform Field Month and Date. Using Outlook 19
Witzker insert Date & Time (HH:mm) no (ss) in userform Using Outlook 6
A insert Date & Time in userform Using Outlook 3
X VBA: Confused with variables between ThisOutlookSession and UserForm Using Outlook 1
M Progrescreas Bar in Outlook UserForm Using Outlook 1
C UserForm and ordering variables Outlook VBA and Custom Forms 3
J userform combobox Outlook VBA and Custom Forms 1
R combobox list in userform Outlook VBA and Custom Forms 1
B Userform Outlook VBA and Custom Forms 5
W Using Excel UserForm from Open Workbook in Outlook VBA Outlook VBA and Custom Forms 5
P userform in VBAProject.otm not working Outlook VBA and Custom Forms 1
N VBA Code Not Working correctly Outlook VBA and Custom Forms 1
P How to get a QR code for automatic signin with Outlook for iOS Using Outlook 5
D Outlook 2021 Using vba code to delete all my spamfolders not only the default one. Outlook VBA and Custom Forms 0
F Color code certain INBOX emails Using Outlook 2
K vba code to auto download email into a specific folder in local hard disk as and when any new email arrives in Inbox/subfolder Outlook VBA and Custom Forms 0
J Want to create a button on the nav bar (module add-in) to run code Outlook VBA and Custom Forms 2
H Preventing the 'email address fetch from Exchange' crashing email reading code Exchange Server Administration 0
C Code to move mail with certain attachment name? Does Not work Outlook VBA and Custom Forms 3
Aussie Outlook 365 Rule runs manually but returns the error code "an unexpected error has occurred" when incoming mail arrives Using Outlook 1
S Need code to allow defined starting folder and selection from there to drill down Outlook VBA and Custom Forms 10
D VBA code to select a signature from the signatures list Outlook VBA and Custom Forms 3
S HTML Code Embedded in String Within Open Outlook Email Preventing Replace(Application.ActiveInspector.CurrentItem.HTMLBody From Working Outlook VBA and Custom Forms 4
P Color Code or highlight folders in Outlook 2016 Using Outlook 2
N Please advise code received new mail Using Outlook 0
B Outlook 2016 Unable to view images or logos on the outlook 2016 emails the same html code works well when i use outlook 2010 Using Outlook 0
S Excel vba code to manage outlook web app Using Outlook 10
S Outlook VBA How to adapt this code for using in a different Mail Inbox Outlook VBA and Custom Forms 0
S Add VBA save code Using Outlook 0
C Auto Run VBA Code on new email Outlook VBA and Custom Forms 1
Witzker Pls help to change the code for inserting date in Ol contact body Outlook VBA and Custom Forms 5
I Outlook 2003 shows html code when To: field is empty Using Outlook 7
F VBA code to dock Styles whenever I write or edit an email Outlook VBA and Custom Forms 0
S Skype for business meeting vba code Outlook VBA and Custom Forms 1
R Expand VBA Permanent Delete Code Outlook VBA and Custom Forms 6
B Outlook Business Contact Manager with SQL to Excel, User Defined Fields in BCM don't sync in SQL. Can I use VBA code to copy 1 field to another? BCM (Business Contact Manager) 0
A VBA Code in Outlook disappears after first use Outlook VBA and Custom Forms 1
Alex Cotton "invalid or unqualified reference" on code that should work Outlook VBA and Custom Forms 5
F VBA to ensure a code is entered in Subject title Outlook VBA and Custom Forms 1

Similar threads

Back
Top