Copy from public contacts to local folder

C

Cecco

Hello

I need a Vbscript that copy all the contacts from a specified public folder
(public folder\all public folder\custom contact) to a local folder.

I've tried with many different script but none of them works.....i dont know
how to get it works...



Thanks in advance for any help.


Stefano
 
S

Sue Mosher [MVP-Outlook]

What in particular didn't work? If you already have it 90% done, there's no point in starting over.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
C

Cecco

I've tried with so many differente scripts, i think it better to create a
brand new one.

i dont know exactly how to make in vbs this tasks.


1. the script will get the public folder thath contains the contact.
2. for each contact in this folder
2.1 copy each contact to local folder

any idea on how to accomplish this?


Regards

Stefano






"Sue Mosher [MVP-Outlook]" <[email protected]> ha scritto nel messaggio
What in particular didn't work? If you already have it 90% done, there's no
point in starting over.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
C

Cecco

I've created a macro for this purpose...


**************************************************************************

Sub Copia()

Dim myOlApp As New Outlook.Application
Dim myNameSpace As Outlook.NameSpace
Dim myContactsFolder As Outlook.MAPIFolder
Dim myNewFolder As Outlook.MAPIFolder
Dim mytrashfolder As Outlook.MAPIFolder
Dim myrashcont As Outlook.MAPIFolder

Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set myContactsFolder = myNameSpace.GetDefaultFolder(olFolderContacts)
Set mysync = myContactsFolder.Folders.Item("BUSINESS CONTACT")
mysync.Delete

Set mypubContact =
myNameSpace.GetDefaultFolder(olPublicFoldersAllPublicFolders).Folders.Item("BUSINESS
CONTACT")
Set myNewFolder = mypubContact.CopyTo(myContactsFolder)

'Sleep 2000
'Set mytrash = myNameSpace.GetDefaultFolder(olFolderDeletedItems)
'Set mytrashcont = mytrash.Folders("BUSINESS CONTACT")
'mytrashcont.Delete

End Sub
**************************************************************************

With this macro the contacts are copied to a subfolder called BUSINESS
CONTACT under my contacts folder.....now the problem is... since i delete
the old contact stored in the BUSINESS CONTACT folder.....these old items
are stored to my deleted item folder and i cannot delete it correctly ( it's
the commented part of the script )






Cecco said:
I've tried with so many differente scripts, i think it better to create a
brand new one.

i dont know exactly how to make in vbs this tasks.


1. the script will get the public folder thath contains the contact.
2. for each contact in this folder
2.1 copy each contact to local folder

any idea on how to accomplish this?


Regards

Stefano






"Sue Mosher [MVP-Outlook]" <[email protected]> ha scritto nel
messaggio What in particular didn't work? If you already have it 90% done, there's
no point in starting over.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers


Cecco said:
Hello

I need a Vbscript that copy all the contacts from a specified public
folder
(public folder\all public folder\custom contact) to a local folder.

I've tried with many different script but none of them works.....i dont
know
how to get it works...



Thanks in advance for any help.


Stefano
 
S

Sue Mosher [MVP-Outlook]

This may be your problem:

Set myNewFolder = mypubContact.CopyTo(myContactsFolder)

As the Help topic for the CopyTo method states:

Copies the current folder in its entirety to the destination folder. Returns a MAPIFolder object that represents the new copy.

In other words, that statement creates a replica of the public folder as a new sub folder under the mypubContact folder that contains a replica of the Contacts folder from your mailbox. Is that what you want? If not, then you need to iterate the items in myPubContact using a For Each ... Next loop and copy each item to the target folder (myContactsFolder), e.g:

For Each itm in mypubContact.Items
Set copy = itm.Copy
copy.Move myContactsFolder
Next
now the problem is... since i delete
the old contact stored in the BUSINESS CONTACT folder.....these old items
are stored to my deleted item folder and i cannot delete it correctly ( it's
the commented part of the script )

'Set mytrash = myNameSpace.GetDefaultFolder(olFolderDeletedItems)
'Set mytrashcont = mytrash.Folders("BUSINESS CONTACT")
'mytrashcont.Delete

What happens when you run that code?
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers


Cecco said:
I've created a macro for this purpose...


**************************************************************************

Sub Copia()

Dim myOlApp As New Outlook.Application
Dim myNameSpace As Outlook.NameSpace
Dim myContactsFolder As Outlook.MAPIFolder
Dim myNewFolder As Outlook.MAPIFolder
Dim mytrashfolder As Outlook.MAPIFolder
Dim myrashcont As Outlook.MAPIFolder

Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set myContactsFolder = myNameSpace.GetDefaultFolder(olFolderContacts)
Set mysync = myContactsFolder.Folders.Item("BUSINESS CONTACT")
mysync.Delete

Set mypubContact =
myNameSpace.GetDefaultFolder(olPublicFoldersAllPublicFolders).Folders.Item("BUSINESS
CONTACT")
Set myNewFolder = mypubContact.CopyTo(myContactsFolder)

'Sleep 2000
'Set mytrash = myNameSpace.GetDefaultFolder(olFolderDeletedItems)
'Set mytrashcont = mytrash.Folders("BUSINESS CONTACT")
'mytrashcont.Delete

End Sub
**************************************************************************

With this macro the contacts are copied to a subfolder called BUSINESS
CONTACT under my contacts folder.....now the problem is... since i delete
the old contact stored in the BUSINESS CONTACT folder.....these old items
are stored to my deleted item folder and i cannot delete it correctly ( it's
the commented part of the script )






Cecco said:
I've tried with so many differente scripts, i think it better to create a
brand new one.

i dont know exactly how to make in vbs this tasks.


1. the script will get the public folder thath contains the contact.
2. for each contact in this folder
2.1 copy each contact to local folder

any idea on how to accomplish this?


Regards

Stefano






"Sue Mosher [MVP-Outlook]" <[email protected]> ha scritto nel
messaggio What in particular didn't work? If you already have it 90% done, there's
no point in starting over.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers


Cecco said:
Hello

I need a Vbscript that copy all the contacts from a specified public
folder
(public folder\all public folder\custom contact) to a local folder.

I've tried with many different script but none of them works.....i dont
know
how to get it works...



Thanks in advance for any help.


Stefano
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top