?
Solved

Another Convert VBA code to VBS code

Posted on 2003-11-03
13
Medium Priority
?
402 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
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.

 
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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month14 days, 14 hours left to enroll

771 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