J
Jonathan Brown
I couldn't find the Visual Basic 6 forum so I thought I'd put this in here.
It applies to Outlook as well. I'm using Visual Basic 6 to develop a form
that will export all my contacts as vcard files. It's supposed to save the
files to my c:\vcards folder as you should see. But visual basic is choking
on my for each...next loop. Here is what I have as my procedure:
Private Sub cmdExport_Click()
Dim oContactsFolder As Outlook.MAPIFolder
Dim oNameSpace As NameSpace
Dim oApp As Outlook.Application
Dim oContact As Outlook.ContactItem
Dim syncSuccess As Boolean
Set oApp = CreateObject("Outlook.Application")
Set oNameSpace = oApp.GetNamespace("MAPI")
Set oContactsFolder = oNameSpace.GetDefaultFolder(olFolderContacts)
'On Error GoTo CreateContacts_Error
'Create New vcard Items
For Each oContact In oContactsFolder
oContact.SaveAs "c:\vcards\" & oContact.FileAs & ".vcf", olVCard
Next oContact
syncSuccess = True
CreateContacts_Exit:
If syncSuccess = True Then
MsgBox "Synchronization was successful", vbInformation
End If
Exit Sub
CreateContacts_Error:
MsgBox "Error#: " & Err.Number & vbCr & Err.Description, vbInformation
syncSuccess = False
GoTo CreateContacts_Exit
End Sub
when I try to run this procedure I get an error message stating the "Object
doesn't support this property or method". When I click debug the highlighted
line is the "for each ocontact in ocontactsfolder" line.
Any reason why I shouldn't be able to loop through my contacts folder and
save each contact as a vcard file?
It applies to Outlook as well. I'm using Visual Basic 6 to develop a form
that will export all my contacts as vcard files. It's supposed to save the
files to my c:\vcards folder as you should see. But visual basic is choking
on my for each...next loop. Here is what I have as my procedure:
Private Sub cmdExport_Click()
Dim oContactsFolder As Outlook.MAPIFolder
Dim oNameSpace As NameSpace
Dim oApp As Outlook.Application
Dim oContact As Outlook.ContactItem
Dim syncSuccess As Boolean
Set oApp = CreateObject("Outlook.Application")
Set oNameSpace = oApp.GetNamespace("MAPI")
Set oContactsFolder = oNameSpace.GetDefaultFolder(olFolderContacts)
'On Error GoTo CreateContacts_Error
'Create New vcard Items
For Each oContact In oContactsFolder
oContact.SaveAs "c:\vcards\" & oContact.FileAs & ".vcf", olVCard
Next oContact
syncSuccess = True
CreateContacts_Exit:
If syncSuccess = True Then
MsgBox "Synchronization was successful", vbInformation
End If
Exit Sub
CreateContacts_Error:
MsgBox "Error#: " & Err.Number & vbCr & Err.Description, vbInformation
syncSuccess = False
GoTo CreateContacts_Exit
End Sub
when I try to run this procedure I get an error message stating the "Object
doesn't support this property or method". When I click debug the highlighted
line is the "for each ocontact in ocontactsfolder" line.
Any reason why I shouldn't be able to loop through my contacts folder and
save each contact as a vcard file?