Results 1 to 4 of 4
  1. #1

    Setting an Object to a currently open Outlook session

    I'm trying some VBScript that will open Outlook then create x amounts of new emails (at the moment i don't want to send them - just create them).

    I want the data for the emails to come from the data table in QTP - but because QTP iterates itself for each row on the data table, I end up with x amounts of outlook sessions.

    Is there anyway that in my function openOutlook() I can get it to check if it's already open and if so, set the Object to the open Outlook rather than create a new one?

    My code is:
    </font><blockquote><font size="1" face="Verdana, Arial, Helvetica">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">Function openOutlook()
    Dim myOlApp
    Dim myNameSpace
    Dim myFolder

    Set myOlApp = CreateObject(&quot;Outlook.Application&quot
    Set myNameSpace = myOlApp.GetNameSpace(&quot;MAPI&quot
    'choose to open the default folder
    Set myFolder= myNameSpace.GetDefaultFolder(6)
    Set openOutlook = myOlApp
    End Function

    Sub newMail(objOutlook, strSubject, strBody)
    Dim objMail
    Set objMail = objOutlook.CreateItem(0) '0 is OLMailItem
    With objMail
    .Subject = strSubject
    .Body = strBody
    End With
    End Sub

    'this is where the code iterates depending on the number of rows in the data table
    newMail openOutlook, DataTable(&quot;Subject&quot;, GlobalSheet),DataTable(&quot;Body&quot;, GlobalSheet)</pre><hr /></blockquote><font size="2" face="Verdana, Arial, Helvetica">many thanks :-)
    Dave :-)

  2. #2

    Re: Setting an Object to a currently open Outlook session

    Here you go...works fine for me. This is all VB stuff, well documented on the Microsoft Site.
    I'm wondering if it's your Set open line that's doing it.....I don't use that line so I'm not sure what it does. As you can see from my code it's pretty much identical and I don't have that problem.

    If you're going to be using Outlook, you'll want to use Redemption as opposed to the way you are doing things, or you'll get security messages popping up all over the place. OutlookRedemption.com I think, or just google it.

    Dim objOutlook
    Dim objNameSpace

    'Create Outlook, Namespace, Folder Objects and Task Item
    Set objOutlook = CreateObject("Outlook.application")
    Set objNameSpace = objOutlook.GetNameSpace("MAPI")

  3. #3

    Re: Setting an Object to a currently open Outlook session

    Remove the line 'myFolder.Display'

  4. #4

    Re: Setting an Object to a currently open Outlook session

    cheers for the help guys i think ive got it sorted now
    Dave :-)



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
BetaSoft Inc.
All times are GMT -8. The time now is 03:39 PM.

Copyright BetaSoft Inc.