Luniz2k1
asked on
Another Convert VBA code to VBS code
Now that I am able to remove Contacts with my prior question, I now have the code to create new contacts. But I need the following code to be able to work inside VBS.
Set OOUTLOOK = New Outlook.Application
Set OCONTACT = Outlook.CreateItem(olConta ctItem)
With OOUTLOOK
With OCONTACT
.FullName = "List-1"
.JobTitle = "Distribution List"
.Email1Address = "someone1@somewhere.com"
.Save
End With
End With
With OOUTLOOK
With OCONTACT
.FullName = "List-2"
.JobTitle = "Distribution List"
.Email1Address = "someone2@somewhere.com"
.Save
End With
End With
Set OOUTLOOK = New Outlook.Application
Set OCONTACT = Outlook.CreateItem(olConta
With OOUTLOOK
With OCONTACT
.FullName = "List-1"
.JobTitle = "Distribution List"
.Email1Address = "someone1@somewhere.com"
.Save
End With
End With
With OOUTLOOK
With OCONTACT
.FullName = "List-2"
.JobTitle = "Distribution List"
.Email1Address = "someone2@somewhere.com"
.Save
End With
End With
ASKER
With only the following code in the VBS:
Set OOUTLOOK = CreateObject("Outlook.Appl ication")
Set OCONTACT = Outlook.CreateItem(olConta ctItem)
OCONTACT.FullName = "List-1"
OCONTACT.JobTitle = "Distribution List"
OCONTACT.Email1Address = "someone1@somewhere.com"
OCONTACT.Save
OCONTACT.FullName = "List-2"
OCONTACT.JobTitle = "Distribution List"
OCONTACT.Email1Address = "someone2@somewhere.com"
OCONTACT.Save
I get the following error:
Script: C:\.........test6.vbs
Line: 2
Char: 1
Error: Object required: 'Outlook'
Code: 800A01A8
Source: Microsoft VBScript runtime error
Set OOUTLOOK = CreateObject("Outlook.Appl
Set OCONTACT = Outlook.CreateItem(olConta
OCONTACT.FullName = "List-1"
OCONTACT.JobTitle = "Distribution List"
OCONTACT.Email1Address = "someone1@somewhere.com"
OCONTACT.Save
OCONTACT.FullName = "List-2"
OCONTACT.JobTitle = "Distribution List"
OCONTACT.Email1Address = "someone2@somewhere.com"
OCONTACT.Save
I get the following error:
Script: C:\.........test6.vbs
Line: 2
Char: 1
Error: Object required: 'Outlook'
Code: 800A01A8
Source: Microsoft VBScript runtime error
is only a tipping error
Set OOUTLOOK = CreateObject("Outlook.Appl ication")
Set OCONTACT = OOUTLOOK.CreateItem(olCont actItem)
Set OOUTLOOK = CreateObject("Outlook.Appl
Set OCONTACT = OOUTLOOK.CreateItem(olCont
and changeAnd change olContactItem constant to its numeric value (i don't remember which one is).
remember as i told you in other Q, don't use constants in VBS, they means nothing to vbscript.
remember as i told you in other Q, don't use constants in VBS, they means nothing to vbscript.
Set OOUTLOOK = CreateObject("Outlook.Appl ication")
Set OCONTACT = OOUTLOOK.CreateItem(olCont actItem)
OCONTACT.FullName = "List-1"
OCONTACT.JobTitle = "Distribution List"
OCONTACT.Email1Address = "someone1@somewhere.com"
OCONTACT.Save
OCONTACT.FullName = "List-2"
OCONTACT.JobTitle = "Distribution List"
OCONTACT.Email1Address = "someone2@somewhere.com"
OCONTACT.Save
Set OCONTACT = OOUTLOOK.CreateItem(olCont
OCONTACT.FullName = "List-1"
OCONTACT.JobTitle = "Distribution List"
OCONTACT.Email1Address = "someone1@somewhere.com"
OCONTACT.Save
OCONTACT.FullName = "List-2"
OCONTACT.JobTitle = "Distribution List"
OCONTACT.Email1Address = "someone2@somewhere.com"
OCONTACT.Save
ASKER
Set OOUTLOOK = CreateObject("Outlook.Appl ication")
Set OCONTACT = OOUTLOOK.CreateItem(10)
OCONTACT.FullName = "List-1"
OCONTACT.JobTitle = "Distribution List"
OCONTACT.Email1Address = "someone1@somewhere.com"
OCONTACT.Save
OCONTACT.FullName = "List-2"
OCONTACT.JobTitle = "Distribution List"
OCONTACT.Email1Address = "someone2@somewhere.com"
OCONTACT.Save
Script: C:\.........test6.vbs
Line: 2
Char: 1
Error: Could not complete the operation. One or more parameter values are not valid.
Code: 80070057
Source: Microsoft Outlook
Set OCONTACT = OOUTLOOK.CreateItem(10)
OCONTACT.FullName = "List-1"
OCONTACT.JobTitle = "Distribution List"
OCONTACT.Email1Address = "someone1@somewhere.com"
OCONTACT.Save
OCONTACT.FullName = "List-2"
OCONTACT.JobTitle = "Distribution List"
OCONTACT.Email1Address = "someone2@somewhere.com"
OCONTACT.Save
Script: C:\.........test6.vbs
Line: 2
Char: 1
Error: Could not complete the operation. One or more parameter values are not valid.
Code: 80070057
Source: Microsoft Outlook
ASKER
Set OOUTLOOK = CreateObject("Outlook.Appl ication")
Set OCONTACT = OOUTLOOK.CreateItem(olCont actItem)
OCONTACT.FullName = "List-1"
OCONTACT.JobTitle = "Distribution List"
OCONTACT.Email1Address = "someone1@somewhere.com"
OCONTACT.Save
OCONTACT.FullName = "List-2"
OCONTACT.JobTitle = "Distribution List"
OCONTACT.Email1Address = "someone2@somewhere.com"
OCONTACT.Save
Script: C:\.........test6.vbs
Line: 3
Char: 9
Error: Object doesn't support this property or method: 'OCONTACT.Fullname'
Code: 800A01B6
Source: Microsoft VBScript runtime error
Set OCONTACT = OOUTLOOK.CreateItem(olCont
OCONTACT.FullName = "List-1"
OCONTACT.JobTitle = "Distribution List"
OCONTACT.Email1Address = "someone1@somewhere.com"
OCONTACT.Save
OCONTACT.FullName = "List-2"
OCONTACT.JobTitle = "Distribution List"
OCONTACT.Email1Address = "someone2@somewhere.com"
OCONTACT.Save
Script: C:\.........test6.vbs
Line: 3
Char: 9
Error: Object doesn't support this property or method: 'OCONTACT.Fullname'
Code: 800A01B6
Source: Microsoft VBScript runtime error
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Set OOUTLOOK = CreateObject("Outlook.Appl ication")
Set OCONTACT = OOUTLOOK.CreateItem(2)
OCONTACT.FullName = "List-1"
OCONTACT.JobTitle = "Distribution List"
OCONTACT.Email1Address = "someone1@somewhere.com"
OCONTACT.Save
OCONTACT.FullName = "List-2"
OCONTACT.JobTitle = "Distribution List"
OCONTACT.Email1Address = "someone2@somewhere.com"
OCONTACT.Save
MsgBox "Addition Of New List- Distribution Lists Complete."
Works ok, except for some reason, It only creates the last one. Even If I have 4:
Set OOUTLOOK = CreateObject("Outlook.Appl ication")
Set OCONTACT = OOUTLOOK.CreateItem(2)
OCONTACT.FullName = "List-1"
OCONTACT.JobTitle = "Distribution List"
OCONTACT.Email1Address = "someone1@somewhere.com"
OCONTACT.Save
OCONTACT.FullName = "List-2"
OCONTACT.JobTitle = "Distribution List"
OCONTACT.Email1Address = "someone2@somewhere.com"
OCONTACT.Save
OCONTACT.FullName = "List-3"
OCONTACT.JobTitle = "Distribution List"
OCONTACT.Email1Address = "someone3@somewhere.com"
OCONTACT.Save
OCONTACT.FullName = "List-4"
OCONTACT.JobTitle = "Distribution List"
OCONTACT.Email1Address = "someone4@somewhere.com"
OCONTACT.Save
MsgBox "Addition Of New List- Distribution Lists Complete."
Only the last contact gets created.
Set OCONTACT = OOUTLOOK.CreateItem(2)
OCONTACT.FullName = "List-1"
OCONTACT.JobTitle = "Distribution List"
OCONTACT.Email1Address = "someone1@somewhere.com"
OCONTACT.Save
OCONTACT.FullName = "List-2"
OCONTACT.JobTitle = "Distribution List"
OCONTACT.Email1Address = "someone2@somewhere.com"
OCONTACT.Save
MsgBox "Addition Of New List- Distribution Lists Complete."
Works ok, except for some reason, It only creates the last one. Even If I have 4:
Set OOUTLOOK = CreateObject("Outlook.Appl
Set OCONTACT = OOUTLOOK.CreateItem(2)
OCONTACT.FullName = "List-1"
OCONTACT.JobTitle = "Distribution List"
OCONTACT.Email1Address = "someone1@somewhere.com"
OCONTACT.Save
OCONTACT.FullName = "List-2"
OCONTACT.JobTitle = "Distribution List"
OCONTACT.Email1Address = "someone2@somewhere.com"
OCONTACT.Save
OCONTACT.FullName = "List-3"
OCONTACT.JobTitle = "Distribution List"
OCONTACT.Email1Address = "someone3@somewhere.com"
OCONTACT.Save
OCONTACT.FullName = "List-4"
OCONTACT.JobTitle = "Distribution List"
OCONTACT.Email1Address = "someone4@somewhere.com"
OCONTACT.Save
MsgBox "Addition Of New List- Distribution Lists Complete."
Only the last contact gets created.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Set OOUTLOOK = CreateObject("Outlook.Appl ication")
Set OCONTACT = OOUTLOOK.CreateItem(2)
OCONTACT.FullName = "List-1"
OCONTACT.JobTitle = "Distribution List"
OCONTACT.Email1Address = "someone1@somewhere.com"
OCONTACT.Save
Set OCONTACT = Nothing
Set OCONTACT = OOUTLOOK.CreateItem(2)
OCONTACT.FullName = "List-2"
OCONTACT.JobTitle = "Distribution List"
OCONTACT.Email1Address = "someone2@somewhere.com"
OCONTACT.Save
Set OCONTACT = Nothing
Set OCONTACT = OOUTLOOK.CreateItem(2)
OCONTACT.FullName = "List-3"
OCONTACT.JobTitle = "Distribution List"
OCONTACT.Email1Address = "someone3@somewhere.com"
OCONTACT.Save
Set OCONTACT = Nothing
Set OCONTACT = OOUTLOOK.CreateItem(2)
OCONTACT.FullName = "List-4"
OCONTACT.JobTitle = "Distribution List"
OCONTACT.Email1Address = "someone4@somewhere.com"
OCONTACT.Save
Set OCONTACT = Nothing
Set OCONTACT = OOUTLOOK.CreateItem(2)
MsgBox "Addition Of New List- Distribution Lists Complete."
Works Like a charm now. Let me go over all of the responses to award points.
Set OCONTACT = OOUTLOOK.CreateItem(2)
OCONTACT.FullName = "List-1"
OCONTACT.JobTitle = "Distribution List"
OCONTACT.Email1Address = "someone1@somewhere.com"
OCONTACT.Save
Set OCONTACT = Nothing
Set OCONTACT = OOUTLOOK.CreateItem(2)
OCONTACT.FullName = "List-2"
OCONTACT.JobTitle = "Distribution List"
OCONTACT.Email1Address = "someone2@somewhere.com"
OCONTACT.Save
Set OCONTACT = Nothing
Set OCONTACT = OOUTLOOK.CreateItem(2)
OCONTACT.FullName = "List-3"
OCONTACT.JobTitle = "Distribution List"
OCONTACT.Email1Address = "someone3@somewhere.com"
OCONTACT.Save
Set OCONTACT = Nothing
Set OCONTACT = OOUTLOOK.CreateItem(2)
OCONTACT.FullName = "List-4"
OCONTACT.JobTitle = "Distribution List"
OCONTACT.Email1Address = "someone4@somewhere.com"
OCONTACT.Save
Set OCONTACT = Nothing
Set OCONTACT = OOUTLOOK.CreateItem(2)
MsgBox "Addition Of New List- Distribution Lists Complete."
Works Like a charm now. Let me go over all of the responses to award points.
why don't you use for loop posted by aelatik?
ASKER
Because I am not reading the data from an external list or database, so a loop wont do me any good.
Set OOUTLOOK = CreateObject("Outlook.Appl
Set OCONTACT = Outlook.CreateItem(olConta
OCONTACT.FullName = "List-1"
OCONTACT.JobTitle = "Distribution List"
OCONTACT.Email1Address = "someone1@somewhere.com"
OCONTACT.Save
OCONTACT.FullName = "List-2"
OCONTACT.JobTitle = "Distribution List"
OCONTACT.Email1Address = "someone2@somewhere.com"
OCONTACT.Save