T
Thomas Gahler
Hi together
I hope this will be the right NG.
When I add a new contact (lastname, firstname, company and some other fields
are filed), I can choose in the '.FileAs'-field from five different entries
1st) - lastname, firstname
2nd) - firstname lastname
3rd) - company
4th) - lastname, firstname (company)
5th) - company (lastname, firstname)
In Word2002 I read the '.FileAs'-property form my contacts and I have
problems with the entry four and five. I just get the first half of the
effective value. [For example, when I store 'Gahler, Thomas (Switzerland
ltd.)' into the '.FileAs'-field, the returned value is only 'Gahler, Thomas'
without the company.]
With 'Windows XP Professional SP1, Word 2002 ( 10.2627.2625)' the code works
proper.
with 'Windows XP Professional SP1, Word 2002 ( 10.4219.4219) SP2' the code
doesn't work anymore.
My questions
- Do you have the same behavior?
- How do I change this misbehaviour?
- How do I get another unique identification for my contacts. I think the
'.EntryID'-property is the best field for that, but I can't use this value
with the '.Restrict'-methode.
(By the way, I know '.FileAs' isn't unique and my original code can handle
that.)
I my original code I read all contacts and add the value of the
'.FileAs'-property to a listbox. After that the user can choose an entry and
all needed data (address, phonenumber etc.) will read from this specific
contact and set into the dokument. But when I don't get the whole entry into
the listbox, I can't find the specific contact an the code get an error.
'---------- Start of Code ----------
'Attribute VB_Name = "Modul1"
Option Explicit
Rem ========================================================================
Rem If «Early binding» is activ, you must set a reference to the
Rem 'Microsoft Outlook 10.0 Object Library'
'Dim olAnw As Outlook.Application
'Dim olOrdner As Outlook.MAPIFolder
'Dim olKontakt As Object 'you can't use «Outlook.ContactItem» because in the
contact folder are contacts, distributionslists and more stored
'Dim olItem As Items
'Dim olItemFilter As Items
Rem If «Late binding» is active, the referenc to the
Rem 'Microsoft Outlook 10.0 Object Library' must not be set.
Rem All used constants must be set here
Dim olAnw As Object
Dim olOrdner As Object
Dim olKontakt As Object
Dim olItem As Object
Dim olItemFilter As Object
Const olFolderContacts As Integer = 10
Const olContactItem As Integer = 2
Const olContact As Integer = 40
Sub Test()
'Get new instance of MS-Outlook
On Error Resume Next
Set olAnw = CreateObject("Outlook.Application")
'If Outlook isn't installed on this PC, ...
If olAnw Is Nothing Then
'...
Else
Documents.Add
'Get Contact-folder
Set olOrdner = olAnw.Session.GetDefaultFolder(olFolderContacts)
'Sort all Contacts
Set olItem = olOrdner.Items
olItem.Sort "[FileAs]"
'Get all Contacts
For Each olKontakt In olItem
With olKontakt
Select Case olKontakt.Class
'Active entry is a «contact»
Case olContact
'Do not read Contacts with an empty '.FileAs'-property
If Not Len(Trim$(.FileAs)) = 0 Then
Selection.TypeText .FileAs
Selection.TypeParagraph
End If
'Active entry is a «distrbutionlist», «?» or «?»
Case Else
'Don't do anything
End Select
End With
Next olKontakt
ActiveDocument.Saved = True
End If
Set olKontakt = Nothing
Set olItem = Nothing
Set olOrdner = Nothing
Set olAnw = Nothing
End Sub
'---------- End of Code ----------
Thanke for every help
I hope this will be the right NG.
When I add a new contact (lastname, firstname, company and some other fields
are filed), I can choose in the '.FileAs'-field from five different entries
1st) - lastname, firstname
2nd) - firstname lastname
3rd) - company
4th) - lastname, firstname (company)
5th) - company (lastname, firstname)
In Word2002 I read the '.FileAs'-property form my contacts and I have
problems with the entry four and five. I just get the first half of the
effective value. [For example, when I store 'Gahler, Thomas (Switzerland
ltd.)' into the '.FileAs'-field, the returned value is only 'Gahler, Thomas'
without the company.]
With 'Windows XP Professional SP1, Word 2002 ( 10.2627.2625)' the code works
proper.
with 'Windows XP Professional SP1, Word 2002 ( 10.4219.4219) SP2' the code
doesn't work anymore.
My questions
- Do you have the same behavior?
- How do I change this misbehaviour?
- How do I get another unique identification for my contacts. I think the
'.EntryID'-property is the best field for that, but I can't use this value
with the '.Restrict'-methode.
(By the way, I know '.FileAs' isn't unique and my original code can handle
that.)
I my original code I read all contacts and add the value of the
'.FileAs'-property to a listbox. After that the user can choose an entry and
all needed data (address, phonenumber etc.) will read from this specific
contact and set into the dokument. But when I don't get the whole entry into
the listbox, I can't find the specific contact an the code get an error.
'---------- Start of Code ----------
'Attribute VB_Name = "Modul1"
Option Explicit
Rem ========================================================================
Rem If «Early binding» is activ, you must set a reference to the
Rem 'Microsoft Outlook 10.0 Object Library'
'Dim olAnw As Outlook.Application
'Dim olOrdner As Outlook.MAPIFolder
'Dim olKontakt As Object 'you can't use «Outlook.ContactItem» because in the
contact folder are contacts, distributionslists and more stored
'Dim olItem As Items
'Dim olItemFilter As Items
Rem If «Late binding» is active, the referenc to the
Rem 'Microsoft Outlook 10.0 Object Library' must not be set.
Rem All used constants must be set here
Dim olAnw As Object
Dim olOrdner As Object
Dim olKontakt As Object
Dim olItem As Object
Dim olItemFilter As Object
Const olFolderContacts As Integer = 10
Const olContactItem As Integer = 2
Const olContact As Integer = 40
Sub Test()
'Get new instance of MS-Outlook
On Error Resume Next
Set olAnw = CreateObject("Outlook.Application")
'If Outlook isn't installed on this PC, ...
If olAnw Is Nothing Then
'...
Else
Documents.Add
'Get Contact-folder
Set olOrdner = olAnw.Session.GetDefaultFolder(olFolderContacts)
'Sort all Contacts
Set olItem = olOrdner.Items
olItem.Sort "[FileAs]"
'Get all Contacts
For Each olKontakt In olItem
With olKontakt
Select Case olKontakt.Class
'Active entry is a «contact»
Case olContact
'Do not read Contacts with an empty '.FileAs'-property
If Not Len(Trim$(.FileAs)) = 0 Then
Selection.TypeText .FileAs
Selection.TypeParagraph
End If
'Active entry is a «distrbutionlist», «?» or «?»
Case Else
'Don't do anything
End Select
End With
Next olKontakt
ActiveDocument.Saved = True
End If
Set olKontakt = Nothing
Set olItem = Nothing
Set olOrdner = Nothing
Set olAnw = Nothing
End Sub
'---------- End of Code ----------
Thanke for every help