Outlook Contacts to vCard (vcf) files

Ik was aan het zoeken op een het internet naar tooltje wat mijn contacten kan exporteren in een keer naar vcf file’s.
Ik vond verschillende tooltjes maar geen een die gratis was.
Tot ik het vb script vond van Dave Moats. Het werkt als een trein.

Aanroep:
C:scripts>cscript exportContacts.vbs /p:C:scriptsoutlookContacts
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

Ward.vcf
Mark.vcf

Script:
==========================================================
‘==     VB Script to Export Outlook Contacts to vCard (vcf) files
‘==
‘==           Copyright © 2008, Dave Moats
‘==
‘== This sample is provided ‘AS-IS’, without any
‘== express or implied warranty. In no event will the
‘== authors be held liable for any damages arising from
‘== the use of this sample code.
‘==
‘== Permission is granted to anyone to use this sample
‘== code for any purpose, including commercial applications,
‘== subject to the following restrictions:
‘==
‘== The origin of this code must not be misrepresented;
‘== you must not claim that you wrote the original code.
‘==
‘== If you use this code, an acknowledgment in the
‘== documentation is requested – shown below:
‘==
‘==             Portions Copyright © 2008,
‘==        Dave Moats (http://www.davemoats.com/).
‘==
‘==========================================================

‘==========================================================
‘== NOTE: watch for wrapped lines and html special
‘==        characters in the web representation of this
‘==        sample code
‘==========================================================

‘==========================================================
‘==
‘== exportContacts.vbs – a script used to export contacts
‘==                        from outlook and save them in
‘==                        vcf format
‘==========================================================
option explicit

‘==========================================================
‘== declare the local variables to be used
‘==========================================================
dim scriptName, namedArgs, folderPath

‘==========================================================
‘== get the name of the running script
‘==========================================================
scriptName = wscript.scriptname

‘==========================================================
‘== get the named command line arguments
‘==========================================================
set namedArgs = wscript.arguments.named

if not namedArgs.exists("p") then
   wscript.echo "Usage: " & scriptName & " /p:<output folder path> is required"
   wscript.echo "Example: cscript " & scriptName & " /p:c:path to the folder"
   wscript.quit
else
   folderPath = namedArgs.item("p")
end if

set namedArgs = nothing

‘==========================================================
‘== now call the subroutine that does all the work
‘==========================================================
exportToVCF folderPath, ".vcf"

wscript.quit

‘==========================================================
‘== sub exportToVCF – subroutine that connects to outlook
‘==                   and exports all contacts to the path
‘==                   specified in the exportPath argument
‘==========================================================
sub exportToVCF(exportPath, ext)
    ‘======================================================
    ‘== declare the local variables
    ‘======================================================
    dim outApp, fldContacts, contactEntry, exp

    ‘======================================================
    ‘== create the outlook object and then get the contacts
    ‘======================================================
    set outApp = createobject("Outlook.Application")
    set fldContacts = outApp.getnamespace("MAPI").getdefaultfolder(10)

    ‘======================================================
    ‘== here we are looping the entries in the contacts
    ‘== folder looking for contacts – when a contact is
    ‘== found it will be exported
    ‘======================================================
    for each contactEntry in fldContacts.items
       if typename(contactEntry) = "ContactItem" then

          dim tmpString, tmpArr, periodLocation, outPath

          tmpString = contactEntry.lastnameandfirstname
          ‘================================================
          ‘== creating the name of the vcf file based on
          ‘== the first and last name fields of the contact
          ‘================================================
          tmpString = replace( tmpString, "’", "" )

          tmpArr = split( tmpString, "," )

          if ubound( tmpArr ) <> 1 then
             wscript.echo tmpString & ext
             outPath = exportPath & "" & tmpString & ext
          else
             if tmpArr(0) = "com" then
                wscript.echo trim(tmpArr(1)) & trim(tmpArr(0)) & ext
                outPath = exportPath & "" & trim(tmpArr(1)) & trim(tmpArr(0)) & ext
             else
                wscript.echo trim(tmpArr(1)) & " " & trim(tmpArr(0)) & ext
                outPath = exportPath & "" & trim(tmpArr(1)) & " " & trim(tmpArr(0)) & ext
             end if
          end if
          contactEntry.saveas outPath, 6

       end if
    next
    ‘======================================================
    ‘== dumping the object references that were created
    ‘======================================================
    set fldContacts = nothing
    set outApp = nothing

end sub

Leave a Reply

Translate »