?
Solved

Another Convert VBA code to VBS code

Posted on 2003-11-03
13
Medium Priority
?
405 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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
 
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 800 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 1200 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month14 days, 2 hours left to enroll

807 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