Moderators SmOke_N Posted October 31, 2006 Moderators Posted October 31, 2006 Minor update... I still can't get it to create new members in the list, but if I remove the lines telling to create a new member, it does create the list, so that's good. The only part that's missing now is the "add new member" section. I've tried dozens of permutations of VB / VBScript code that I've found, but nothing's worked so far. Then again, I know almost nothing about VB / VBScript, and I certainly don't know enough to combine the VB code with the AutoIt code.If there is a VB script that works that you know of, post it here, and someone is sure to translate it for you if you're having this many issues still . Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
Omatsei Posted October 31, 2006 Author Posted October 31, 2006 (edited) There's apparently a couple different methods of doing it, but I can't verify that either works... this one is from MSDN: Sub AddNewMembers() Dim myOlApp As New Outlook.Application Dim myNameSpace As Outlook.NameSpace Dim myDistList As Outlook.DistListItem Dim myTempItem As Outlook.MailItem Dim myRecipients As Outlook.Recipients Set myNameSpace = myOlApp.GetNamespace("MAPI") Set myDistList = myOlApp.CreateItem(olDistributionListItem) Set myTempItem = myOlApp.CreateItem(olMailItem) Set myRecipients = myTempItem.Recipients myDistList.DLName = _ InputBox("Enter the name of the new distribution list") myRecipients.Add myNameSpace.CurrentUser.Name myRecipients.Add "Dan Wilson" myRecipients.ResolveAll myDistList.AddMembers myRecipients myDistList.Save myDistList.Display End Sub My code (currently) looks like this: if $emailaddress[0] <= 2 Then if $alias = "alias" Then $objOutlook = ObjCreate( "Outlook.Application" ) $objContact = $objOutlook.CreateItem( 2 ) $objContact.FullName = $name $objContact.Email1Address = $emailaddress[1] $objContact.Save EndIf Else ; If there's more than 1 email address, create a distribution list and add them if $alias = "alias" Then $objOutlook = ObjCreate( "Outlook.Application" ) $objDistributionList = $objOutlook.CreateItem( 7 ) $objDistributionList.DLName = $name ; Temp object needed for recipient list $objTempMail = $objOutlook.CreateItem( 1 ) $objRecipients = $objTempMail.Recipients for $z = 1 to $emailaddress[0] $objRecipients.Add($emailaddress[$z]) $objRecipients.ResolveAll next $objDistributionList.Save $objTempMail.Close( 1 ) EndIf EndIf My code looks at each line of text, and if the line begins with "alias", it analyzes the 3rd field, which is where the e-mail address goes. If there's only 1 address (it says <= 2 because there is usually a comma after the address, so the 2nd field in that case is null), it creates a new contact. If there's more than 2 addresses, it creates a distribution list... except that it won't add new members. Edited October 31, 2006 by Omatsei
Locodarwin Posted October 31, 2006 Posted October 31, 2006 Are you getting an error on that code? If so, on which line? -S (Yet Another) ExcelCOM UDF"A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly...[indent]...specialization is for insects." - R. A. Heinlein[/indent]
Omatsei Posted October 31, 2006 Author Posted October 31, 2006 I just modified it a little... sorry... but yes, I'm getting the same error I've been getting for a while. Here's the current snippet: if $emailaddress[0] = 2 And $emailaddress[2] = "" Then if $alias = "alias" Then $objOutlook = ObjCreate( "Outlook.Application" ) $objContact = $objOutlook.CreateItem( 2 ) $objContact.FullName = $name $objContact.Email1Address = $emailaddress[1] $objContact.Save EndIf Else ; If there's more than 1 email address, create a distribution list and add them if $alias = "alias" Then $objOutlook = ObjCreate( "Outlook.Application" ) $objDistributionList = $objOutlook.CreateItem( 7 ) $objDistributionList.DLName = $name $objTempItem = $objOutlook.CreateItem( 1 ) $myRecipients = $objTempItem.Recipients for $z = 1 to $emailaddress[0] $myRecipients.Add $emailaddress[$z] next $objDistributionList.AddMembers $myRecipients $objDistributionList.Save $objTempItem.Close( 1 ) EndIf EndIf With that code, a popup asks if I want to allow access to Outlook, I click yes, then it comes back with: The requested action with this object has filed.: $myRecipients.Add $emailaddress[$z] $myRecipients.Add ^ ERROR I've tried using both .Add and .AddMembers, but neither of them gives me any more info... it just fails at the same spot.
Locodarwin Posted October 31, 2006 Posted October 31, 2006 Okay. Put the following code somewhere in yours: Func MyErrFunc() $HexNumber=hex($oMyError.number,8) Msgbox(0,""," I've intercepted a nasty COM Error!" & @CRLF & _ "Error Number: " & $HexNumber & @CRLF & _ "WinDescription: " & $oMyError.windescription & @CRLF & _ "Error Description: " & $oMyError.description & @CRLF & _ "Help File: " & $oMyError.helpfile & @CRLF & _ "Help ID: " & $oMyError.helpcontext & @CRLF & _ "Script Line: " & $oMyError.scriptline & @CRLF) SetError(1) ; something to check for when this function returns EndfuncoÝ÷ Ù8^¶¬)޲«zw®Ø^¶h*.Êy«¢+Ø(ÀÌØí½5åÉɽÈô=©Ù¹Ð ÅÕ½ÐíÕѽ%йÉɽÈÅÕ½Ðì°ÅÕ½Ðí5åÉÉÕ¹ÅÕ½Ðì¤(oÝ÷ Ù8b³¥)쵩eh#zºè®§vW«Z#f{^ë-yاËayh§ ëzºè®í«ewÈz{ZÉh±ì¨º°2«jgz»"^*.ßÚÞq©exëa¡ÛajÚÞªè«zÊZ©µêìjëh×6 $objDistributionList.AddMembers($myRecipients) That might be the problem. -S (Yet Another) ExcelCOM UDF"A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly...[indent]...specialization is for insects." - R. A. Heinlein[/indent]
Omatsei Posted October 31, 2006 Author Posted October 31, 2006 I did that, and here's the message: I've intercepted a nasty COM Error! Error Number: 80020009 WinDescription: Error Description: There must be at least one name or distribution list in the To, Cc, or Bcc box. Help File: Help ID: 0 Script Line: 52 Here's the entirety of my code... sorry for posting such a long message... expandcollapse popup#cs ---------------------------------------------------------------------------- AutoIt Version: 3.1.1.0 Author: Shannon Johnson Script Function: Install Eudora from the Common Drive. #ce ---------------------------------------------------------------------------- ;#noicontray ;#include <GUIConstants.au3> #include <File.au3> ;Opt("TrayIconHide", 1) Opt("WinTitleMatchMode", 2) ;SplashTextOn( "Eudora Address Book Converter", "This program will insert all of your Eudora Addresses into Outlook. While this screen is up, please do not touch your computer. It will only take a few minutes.", 300, 200) $oMyError = ObjEvent("AutoIt.Error","MyErrFunc") Dim $nndbase _FileReadToArray( "C:\mail\nndbase.txt", $nndbase ) for $i = 1 to $nndbase[0] ; IF THE LINE HAS A DOUBLE-QUOTE AND A COMMA if StringinStr( $nndbase[$i], Chr("34") ) And StringinStr( $nndbase[$i], Chr("44") ) Then $record = StringSplit( $nndbase[$i], Chr("34") ) $alias = StringStripWS( $record[1], 8 ) $name = $record[2] $emailaddress = StringSplit( StringStripWS( $record[3], 8 ), Chr("44") ) ; If there is only 1 email address, add them as a contact if $emailaddress[0] = 2 And $emailaddress[2] = "" Then if $alias = "alias" Then $objOutlook = ObjCreate( "Outlook.Application" ) $objContact = $objOutlook.CreateItem( 2 ) $objContact.FullName = $name $objContact.Email1Address = $emailaddress[1] $objContact.Save EndIf Else ; If there's more than 1 email address, create a distribution list and add them if $alias = "alias" Then $objOutlook = ObjCreate( "Outlook.Application" ) $objDistributionList = $objOutlook.CreateItem( 7 ) $objDistributionList.DLName = $name $objTempItem = $objOutlook.CreateItem( 1 ) $myRecipients = $objTempItem.Recipients for $z = 1 to $emailaddress[0] $myRecipients.Add($emailaddress[$z]) next $objDistributionList.AddMembers($myRecipients) $objDistributionList.Save $objTempItem.Close( 1 ) EndIf EndIf ; IF THE LINE HAS A DOUBLE-QUOTE BUT NO COMMA ElseIf StringinStr( $nndbase[$i], Chr("34") ) and Not StringinStr( $nndbase[$i], Chr("44") ) Then $record = StringSplit( $nndbase[$i], Chr("34") ) $alias = StringStripWS( $record[1], 8 ) $name = $record[2] $emailaddress = $record[3] if $alias = "alias" Then $objOutlook = ObjCreate( "Outlook.Application" ) $objContact = $objOutlook.CreateItem( 2 ) $objContact.FullName = $name $objContact.Email1Address = $emailaddress $objContact.Save EndIf ; IF THE LINE HAS NO DOUBLE-QUOTE BUT DOES HAVE A COMMA ElseIf StringinStr( $nndbase[$i], Chr("44") ) And Not StringinStr( $nndbase[$i], Chr("34") ) then $record = StringSplit( $nndbase[$i], Chr("44") ) ; Split the first section by spaces $nameandaddy = StringSplit( $record[1], Chr("32") ) if $nameandaddy[1] = "alias" Then $name = $nameandaddy[2] $firstemail = $nameandaddy[3] ; If there is only 1 email address, add them as a contact if $record[0] = 2 And $record[2] = "" Then $objOutlook = ObjCreate( "Outlook.Application" ) $objContact = $objOutlook.CreateItem( 2 ) $objContact.FullName = $name $objContact.Email1Address = $firstemail $objContact.Save ; If there are more than 1 email address, add them as a distribution list and add the emails Else $objOutlook = ObjCreate( "Outlook.Application" ) $objDistributionList = $objOutlook.CreateItem( 7 ) $objDistributionList.DLName = $name ; $objDistributionList.AddNewMember = $firstemail for $z = 2 to $record[0] ; $objDistributionList.AddNewMember = $record[$z] Next $objDistributionList.Save EndIf EndIf ; IF THE LINE HAS NEITHER A DOUBLE-QUOTE NOR A COMMA Else $record = StringSplit( $nndbase[$i], Chr("32") ) if $record[0] > 1 Then $alias = StringStripWS( $record[1], 8 ) $name = $record[2] $emailaddress = $record[3] if $alias = "alias" Then $objOutlook = ObjCreate( "Outlook.Application" ) $objContact = $objOutlook.CreateItem( 2 ) $objContact.FullName = $name $objContact.Email1Address = $emailaddress $objContact.Save EndIf EndIf EndIf Next Func MyErrFunc() $HexNumber=hex($oMyError.number,8) Msgbox(0,""," I've intercepted a nasty COM Error!" & @CRLF & _ "Error Number: " & $HexNumber & @CRLF & _ "WinDescription: " & $oMyError.windescription & @CRLF & _ "Error Description: " & $oMyError.description & @CRLF & _ "Help File: " & $oMyError.helpfile & @CRLF & _ "Help ID: " & $oMyError.helpcontext & @CRLF & _ "Script Line: " & $oMyError.scriptline & @CRLF) SetError(1); something to check for when this function returns Endfunc I had to re-write it a few times, so it probably looks quite a bit different from my original message, but there it is. Thanks for all your help!
Omatsei Posted October 31, 2006 Author Posted October 31, 2006 I just ran that code, and if I hit OK a bunch of times, it actually works! It does insert the addresses into the distribution lists! If I remove the MyErrFunc() and the line at the top calling that function, it dies again... but at least that tells me that if I can somehow tell it to ignore the error, then it might work.
Locodarwin Posted October 31, 2006 Posted October 31, 2006 I just ran that code, and if I hit OK a bunch of times, it actually works! It does insert the addresses into the distribution lists! If I remove the MyErrFunc() and the line at the top calling that function, it dies again... but at least that tells me that if I can somehow tell it to ignore the error, then it might work.Well, you could fill the COM error routine with do-nothing code. Or perhaps send the output to the console instead of a MsgBox.That's not really the preferred solution, but at least your script will work until such time as we can figure out the problem. It takes the pressure off. -S (Yet Another) ExcelCOM UDF"A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly...[indent]...specialization is for insects." - R. A. Heinlein[/indent]
Omatsei Posted October 31, 2006 Author Posted October 31, 2006 I managed to get it all working! Here's the full blown code that I'm using now... expandcollapse popup#cs ---------------------------------------------------------------------------- AutoIt Version: 3.1.1.0 Author: Shannon Johnson Script Function: Convert Eudora Address Book to Outlook. #ce ---------------------------------------------------------------------------- ;#noicontray ;#include <GUIConstants.au3> #include <File.au3> ;Opt("TrayIconHide", 1) Opt("WinTitleMatchMode", 2) SplashTextOn( "Eudora Address Book Converter", "Please wait while we import your addresses into Outlook." & @LF & @LF & "If you see a warning that a program is trying to access your contacts, click ""Allow access for 5 minutes"" and then OK." & @LF & @LF & "This process will only take a couple minutes.", 300, 200, 100, 100) $oMyError = ObjEvent("AutoIt.Error","MyErrFunc") Dim $nndbase _FileReadToArray( "C:\mail\nndbase.txt", $nndbase ) $objsecurity = ObjCreate("SecurityManager.DisableOOMWarnings") $objsecurity = "True" for $i = 1 to $nndbase[0] ; IF THE LINE HAS A DOUBLE-QUOTE AND A COMMA if StringinStr( $nndbase[$i], Chr("34") ) And StringinStr( $nndbase[$i], Chr("44") ) Then $record = StringSplit( $nndbase[$i], Chr("34") ) $alias = StringStripWS( $record[1], 8 ) $name = $record[2] $emailaddress = StringSplit( StringStripWS( $record[3], 8 ), Chr("44") ) ; If there is only 1 email address, add them as a contact if $emailaddress[0] = 2 And $emailaddress[2] = "" Then if $alias = "alias" Then $objOutlook = ObjCreate( "Outlook.Application" ) $objContact = $objOutlook.CreateItem( 2 ) $objContact.FullName = $name $objContact.Email1Address = $emailaddress[1] $objContact.Save EndIf Else ; If there's more than 1 email address, create a distribution list and add them if $alias = "alias" Then $objOutlook = ObjCreate( "Outlook.Application" ) $objDistributionList = $objOutlook.CreateItem( 7 ) $objDistributionList.DLName = $name $objTempItem = $objOutlook.CreateItem( 1 ) $myRecipients = $objTempItem.Recipients for $z = 1 to $emailaddress[0] $myRecipients.Add($emailaddress[$z]) next $objDistributionList.AddMembers($myRecipients) $objDistributionList.Save $objTempItem.Close( 1 ) EndIf EndIf ; IF THE LINE HAS A DOUBLE-QUOTE BUT NO COMMA ElseIf StringinStr( $nndbase[$i], Chr("34") ) and Not StringinStr( $nndbase[$i], Chr("44") ) Then $record = StringSplit( $nndbase[$i], Chr("34") ) $alias = StringStripWS( $record[1], 8 ) $name = $record[2] $emailaddress = $record[3] if $alias = "alias" Then $objOutlook = ObjCreate( "Outlook.Application" ) $objContact = $objOutlook.CreateItem( 2 ) $objContact.FullName = $name $objContact.Email1Address = $emailaddress $objContact.Save EndIf ; IF THE LINE HAS NO DOUBLE-QUOTE BUT DOES HAVE A COMMA ElseIf StringinStr( $nndbase[$i], Chr("44") ) And Not StringinStr( $nndbase[$i], Chr("34") ) then $record = StringSplit( $nndbase[$i], Chr("44") ) ; Split the first section by spaces $nameandaddy = StringSplit( $record[1], Chr("32") ) if $nameandaddy[1] = "alias" Then $name = $nameandaddy[2] $firstemail = $nameandaddy[3] ; If there is only 1 email address, add them as a contact if $record[0] = 2 And $record[2] = "" Then $objOutlook = ObjCreate( "Outlook.Application" ) $objContact = $objOutlook.CreateItem( 2 ) $objContact.FullName = $name $objContact.Email1Address = $firstemail $objContact.Save ; If there are more than 1 email address, add them as a distribution list and add the emails Else $objOutlook = ObjCreate( "Outlook.Application" ) $objDistributionList = $objOutlook.CreateItem( 7 ) $objDistributionList.DLName = $name $objTempItem = $objOutlook.CreateItem( 1 ) $myRecipients = $objTempItem.Recipients $myRecipients.Add($firstemail) for $z = 2 to $record[0] $myRecipients.Add($record[$z]) next $objDistributionList.AddMembers($myRecipients) $objDistributionList.Save $objTempItem.Close( 1 ) EndIf EndIf ; IF THE LINE HAS NEITHER A DOUBLE-QUOTE NOR A COMMA Else $record = StringSplit( $nndbase[$i], Chr("32") ) if $record[0] > 1 Then $alias = StringStripWS( $record[1], 8 ) $name = $record[2] $emailaddress = $record[3] if $alias = "alias" Then $objOutlook = ObjCreate( "Outlook.Application" ) $objContact = $objOutlook.CreateItem( 2 ) $objContact.FullName = $name $objContact.Email1Address = $emailaddress $objContact.Save EndIf EndIf EndIf Next Func MyErrFunc() Endfunc A couple things I'd like to add... first, the option to browse to locate the nndbase.txt file, if it's not in C:\mail... I think I can handle that much. Second, and one that I tried briefly to automate, but ran into some trouble, is the disabling of the dumb security warning that pops up saying that a program is trying to access the Outlook contacts. Finally, the last thing would be to create a separate Contacts folder within Outlook called something like "Eudora Address Book" and put all the contacts in there instead of directly in the main contacts folder. I'll play around with it all some more tomorrow. Thanks for all your help! I never could have got it working without you!
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now