Solved

Another Convert VBA code to VBS code

Posted on 2003-11-03
13
397 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA Shell can't Find Word document 11 154
Passing a Text Box name to a Sub 6 104
Export Data to Different .csv Files 27 131
Assign a value in Excel V-Basic 3 36
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

738 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