Solved

Another Convert VBA code to VBS code

Posted on 2003-11-03
13
392 Views
Last Modified: 2010-05-01
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(olContactItem)
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
0
Comment
Question by:Luniz2k1
  • 6
  • 4
  • 3
13 Comments
 
LVL 14

Expert Comment

by:aelatik
ID: 9671703
Try this

Set OOUTLOOK = CreateObject("Outlook.Application")
Set OCONTACT = Outlook.CreateItem(olContactItem)
        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
0
 
LVL 5

Author Comment

by:Luniz2k1
ID: 9671765
With only the following code in the VBS:

Set OOUTLOOK = CreateObject("Outlook.Application")
Set OCONTACT = Outlook.CreateItem(olContactItem)
        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
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9671889
is only a tipping error
Set OOUTLOOK = CreateObject("Outlook.Application")
Set OCONTACT = OOUTLOOK.CreateItem(olContactItem)
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9671910
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.
0
 
LVL 14

Expert Comment

by:aelatik
ID: 9671927
Set OOUTLOOK = CreateObject("Outlook.Application")
Set OCONTACT = OOUTLOOK.CreateItem(olContactItem)
        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
0
 
LVL 5

Author Comment

by:Luniz2k1
ID: 9671948
Set OOUTLOOK = CreateObject("Outlook.Application")
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
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 5

Author Comment

by:Luniz2k1
ID: 9671961
Set OOUTLOOK = CreateObject("Outlook.Application")
Set OCONTACT = OOUTLOOK.CreateItem(olContactItem)
        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
0
 
LVL 16

Assisted Solution

by:Richie_Simonetti
Richie_Simonetti earned 200 total points
ID: 9672220
olContactItem = 2 not 10
0
 
LVL 5

Author Comment

by:Luniz2k1
ID: 9672278
Set OOUTLOOK = CreateObject("Outlook.Application")
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.Application")
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.
0
 
LVL 14

Accepted Solution

by:
aelatik earned 300 total points
ID: 9672320
try clearing OCONTACT:

Set OOUTLOOK = CreateObject("Outlook.Application")
For i = 1 To 4
Set OCONTACT = OOUTLOOK.CreateItem(2)
        OCONTACT.FullName = "List-" & i
        OCONTACT.JobTitle = "Distribution List"
        OCONTACT.Email1Address = "someone1@somewhere.com"
        OCONTACT.Save
Set OCONTACT = Nothing
Next
0
 
LVL 5

Author Comment

by:Luniz2k1
ID: 9672354
Set OOUTLOOK = CreateObject("Outlook.Application")
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.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9672548
why don't you use for loop posted by aelatik?
0
 
LVL 5

Author Comment

by:Luniz2k1
ID: 9672650
Because I am not reading the data from an external list or database, so a loop wont do me any good.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now