UserForm Code For Contact Links

Status
Not open for further replies.
Any update today from the Smart Woman???? ;) In the past you have given me the full code to copy and paste to the VBA....and this time, I do need the full code based on what I showed you and you know what to put and where!!!! And I would be very excited to get this done!!! ;)
 
I was given the following from someone that sorts the combobox for Categories....so if you see this, what should I do to sort the combobox for the Contacts that show up:

He changed the Private Sub UserForm_Initialize() and added a Function below it

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
' Declare variable to use
Dim arrCategories() ' the array
Dim i As Long
Dim lngCount As Long
Dim arrSorted() As Variant ' Results of sorting held here
Dim First As Integer
Dim Last As Integer

Set objOutlook = CreateObject("Outlook.Application")


' Initialize i to zero
i = 0 ' Used later when populating array

' Determine what size the array will be
lngCount = Application.Session.Categories.Count

' Resize array with determined size
ReDim arrCategories(lngCount)
ReDim arrSorted(lngCount)
' Start populating array with categories
For Each Category In Application.Session.Categories
arrCategories(i) = Category
i = i + 1
Next
' Call the sorting function and store the sorted array in variable
arrSorted = f_SortArray(arrCategories)

' Using the newly sorted array as the source to the drop-down, traverse it adding
' elements as items to drop-down list
First = LBound(arrSorted)
Last = UBound(arrSorted)
For i = First To Last - 1
Me.ddlCategories.addItem arrSorted(i)
Next i
' The drop-down list should now be sorted
' Take this model in your ddlContacts_Change event


End Sub

Function f_SortArray(ArrayToSort() As Variant) As Variant

Dim First As Integer
Dim Last As Integer
Dim i As Integer
Dim j As Integer
Dim Temp As String

First = LBound(ArrayToSort)
Last = UBound(ArrayToSort)
For i = First To Last - 1
For j = i + 1 To Last
If ArrayToSort(i) > ArrayToSort(j) Then
Temp = ArrayToSort(j)
ArrayToSort(j) = ArrayToSort(i)
ArrayToSort(i) = Temp
End If
Next j
Next i
f_SortArray = ArrayToSort

End Function
 
I sent another email. And would love to hear back from the Smart Woman!!
 
I'm not that smart. :)

This is part of what needs changed (plus some category stuff later in the code):

you need to count contacts

lngCount = Application.Session.Categories.Count

lngCount = MyContacts.items.Count

(lngCount = MyItem.Count might work too)
' Resize array with determined size
arrCategories is just the variable for the array, no need ot change it, except to avoid confusion.
ReDim arrCategories(lngCount)
ReDim arrSorted(lngCount)
' Start populating array with categories

this needs changed,

For Each Category In Application.Session.Categories

to

For Each MyItem In MyContacts
arrCategories(i) = Category
 
As to lngCount = MyContacts.items.Count or lngCount = MyItem.Count , do I replace lngCount = Application.Session.Categories.Count? And then do I just replace For Each Category In Application.Session.Categories with For Each MyItem In MyContacts arrCategories(i) = Category ? And does that affect the sorting of the Categories or just update for both Categories and Contacts to be sorted?
 
And can you just make all the changes you suggest and anything else as you said needs to adjusted re Categories, so I can just copy and past it and see if it works or tell you the errors etc.??? Thanks so much to he Smart Woman!!!;)
 
yes, replace the lngCout line with one of the ones i suggested and see if it works.

The function will work with contacts and categories and each one has it's own macro. I don't know if it will affect the category sorting, it shouldn't though. I don't have multiple contacts folders and didn't test it.
 
And then do I just replace For Each Category In Application.Session.Categories with For Each MyItem In MyContacts arrCategories(i) = Category ?
 
I tried both ways and error is 424 "Object required"
 
Possible update tonight?

No, mostly because i cant figure out what object is missing. Unless you don't have a dim statement for one of the objects.
 
If you look real quick at the full code per what you gave me to add, what added dim doi put in please??
 
That's why I'm not sure what object is missing - the code looks good. I'm obviously missing something though. Try adding

dim myitem as object

don't know if its the board software, but

arrCategories(i) = Category

needs to be on it's own line, not one line with For Each MyItem In MyContacts
 
Thank you. But as I repeat, i don't understand it all. Please give me the specific code lines and where exactly where to put them as I don't understand the concepts.
 
Any full update so I have the code which already sorts the Categories and you update the full code to sort the Contacts from all folders together....any chance today or tomorrow?
 
No, no update because i can't get anything to work. I have no idea what I'm missing - it's really above my level of expertize.
 
Got it....and just in case you figure it out, please let me know
 
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
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
Z Outlook Custom Form: Adding Dropdown(Project Code) at the end of subject Outlook VBA and Custom Forms 0

Similar threads

Back
Top