Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sending an email from Attachmate

Status
Not open for further replies.

lmbayley

Technical User
Apr 16, 2007
30
CA
I’m working on a macro that gathers a screenful of information, determines an email address, and creates an Outlook message with the scraped screen in the body.

My code works beautifully when run straight from Outlook; the problem is that when I have to update the code, I end up going desk to desk to get everybody up and running. I’m trying to migrate the code to Extra! Basic so that a) it can be run from an Attachmate toolbar button, and b) so that I can store the code on a network drive and make seamless updates.

Last week I deployed the Extra! version of the macro, and it ran fine for the first few days. Then on Friday I got reports of the following from a number of different users:

· The email was completed correctly on the user’s screen, but when she printed a copy only the To: & Subject: lines were shown. No text at all.
· When verifying the email in her sent messages folder, the user got a pop up stating "Can't open this item. Unknown error."
· The recipient was unable to open the message.

I had the same problems when I tried to use Excel as a platform to run the macro.

For Outlook, I used these object declarations:
Code:
Dim ns As NameSpace
Set ns = ThisOutlookSession.Session
Dim SDRequest As MailItem
Set SDRequest = CreateItem(olMailItem)

For Excel, I used these object declarations:

Code:
Set ol = CreateObject("Outlook.Application")
Set ns = ol.GetNamespace("MAPI")
Dim SDRequest As MailItem
Set SDRequest = ol.CreateItem(olMailItem)


Here’s what my Extra Basic code looks like (by the way, we’re running Extra 6.7 here):

Code:
global OutlookApp as object
global SDRequest as object

Sub Main
    
    
    Set OutlookApp = CreateObject("Outlook.Application")
    Set SDRequest = OutlookApp.CreateItem(0)
    
‘    code to initialize screen objects    
    
‘    code to determine the appropriate recipient address

‘    code to get the screen information into the email
        
    For ScreenLine = 4 To 11
        ScreenArray(ScreenLine) = Sess0.Screen.Area(ScreenLine, 2, screenline,80)
    Next ScreenLine
                
        
    For ScreenLine = 4 To 11
        BodyText = BodyText & ScreenArray(ScreenLine) & Chr(13)
    Next ScreenLine
        
       
    on error goto ErrHandler
    SDRequest.Display   ' this causes Outlook to ask whether to 
                        ‘ permit the use of the address book
                        ' if the user says NO, there is an error
                      
    SDRequest.Recipients.Add (AppropriateEmailAddress)
    SDRequest.Body = BodyText        
    SDRequest.Subject = SubjectLine
    SDRequest.ReadReceiptRequested = True
                
End If
    
Cleanup:    
    set OutlookApp = nothing
    set SDRequest = nothing        
        
    exit sub
       
ErrHandler:
    msgbox("You chose not to allow the macro to access your address book.  Unable to send request.")
    SDRequest.Delete
    
    resume Cleanup
        
End Sub

Has anyone else run into this kind of problem? Is there something I should be doing differently in the code?

Thanks for your time and help!
 
Just to let you all know, the answer was dropped into my lap by accident late last week. It turns out that all of my coding was correct. BUT..., if the user makes any changes whatsoever to the email created by the macro, that's when the problems crop up. The users were adding their signatures to their emails. This wasn't a problem when the macro was being launched from Outlook itself, but became a problem when the macro was running from Attachmate.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top