hey guys! I'd like to crate a vbs script which could load specific data from a file.. name, lastname, e-mail e.g. john, smith, world, john@world.com and so on.. and then create a new contact in outlook application using those values. To create a new contact i could you sth like this: Const olContactItem = 2a Dim objOutl, objContact Set objOutl = WScript.CreateObject("Outlook.Application") Set objContact = objOutl.CreateItem(olContactItem) objContact.FirstName = "john" objContact.LastName = "smith" objContact.Email1Address = "john@world.com" objContact.Save() But i'm not able to create a procedure which could load that data from a file, could you please help me with that. Jack
Here is a simple solution to the problem. Code: Const InpFile = "C:\contacts.csv" 'Import file Const olContactItem = 2a Dim objOutl, objContact,oTF,oFSO Set oFSO = CreateObject("Scripting.FileSystemObject") Set oTF = oFSO.OpenTextFile(InpFile,ForReading,True) Set objOutl = WScript.CreateObject("Outlook.Application") Do While oTF.AtEndOfStream <> True sLine = oTF.ReadLine aLine = split(sline, ",",-1,1) sFname = aLine(0) sLname = aLine(1) sEmail = aLine(2) Set objContact = objOutl.CreateItem(olContactItem) objContact.FirstName = sFname objContact.LastName = sLname objContact.Email1Address = sEmail objContact.Save() Set objContact = Nothing Loop
thanks for help! just one thing, when im trying to run it, i got an error: "Expected end of statement" so i removed 'a' from ' Const olContactItem = 2a' then i got an error: "Invalid procedure call or argument" in this line: "Set oTF = oFSO.OpenTextFile(InpFile,ForReading,True)" i tried to add 'Option Explicit' but then i get: "variable is undefined: 'For Reading''" ...
You need to include the library with the constant definitions the post here http://p2p.wrox.com/archive/beginning_asp/2002-06/53.asp explains. the line you need to add goes before the <head> it should read : <!-- METADATA TYPE=3D"typelib" FILE=3D"C:\windows\system32\scrrun.dll" --> Note: the location of scrrun.dll may differ and is system dependant. Dale
I'd like to do the same thing but also create some distribution lists at the same time. I am a complete newbie when it comes to this- can I drop that code (listed above) in a .wsf file and run it from the commandline? Also, when I looked at the library to include, it seems you are including it as it would be on a webpage- I assume the syntax would be completely different in a .wsf file on a local machine, but have no clue what that syntax would be. Any help would be greatly appreciated, Thanks -Tom