UserForm Code For Contact Links

Status
Not open for further replies.

LMS

Senior Member
Outlook version
Email Account
Exchange Server
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!!! ;)
 

LMS

Senior Member
Outlook version
Email Account
Exchange Server
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
 

LMS

Senior Member
Outlook version
Email Account
Exchange Server
I sent another email. And would love to hear back from the Smart Woman!!
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
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
 

LMS

Senior Member
Outlook version
Email Account
Exchange Server
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?
 

LMS

Senior Member
Outlook version
Email Account
Exchange Server
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!!!;)
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
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.
 

LMS

Senior Member
Outlook version
Email Account
Exchange Server
And then do I just replace For Each Category In Application.Session.Categories with For Each MyItem In MyContacts arrCategories(i) = Category ?
 

LMS

Senior Member
Outlook version
Email Account
Exchange Server
I tried both ways and error is 424 "Object required"
 

LMS

Senior Member
Outlook version
Email Account
Exchange Server
If you look real quick at the full code per what you gave me to add, what added dim doi put in please??
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
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
 

LMS

Senior Member
Outlook version
Email Account
Exchange Server
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.
 

LMS

Senior Member
Outlook version
Email Account
Exchange Server
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?
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
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.
 

LMS

Senior Member
Outlook version
Email Account
Exchange Server
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
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
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
D Any updates or fixes that would make this code stop working just moving emails to another folder Outlook VBA and Custom Forms 1
N Open & Save VBAProject.Otm using VBA Code Outlook VBA and Custom Forms 1
M error code 0x8DE00006 Using Outlook 1
R VBA Code to permanently delete selected email Outlook VBA and Custom Forms 10
dyny723 Outlook 2016: Code to link a contact to emails received from that contact Outlook VBA and Custom Forms 1
D Command Button code will not execute. Any suggestions Please. Outlook VBA and Custom Forms 2

Similar threads

Top